Access rendering settings in DevTools programmatically from a Chrome extension - javascript

here is my problem :
What I want :
I'm wondering if it's possible to have access (to change them) to renderings settings from an extension in Chrome. I know some APIs exist like DevTools API but I cannot find a way to change any of these rendering settings from my extension.
Rendering tab in DevTools
What I want more specifically :
I made a Chrome extension and I want it to make a specific tab think it's focused, even if it's not.
I know I can do it manually by opening Chrome DevTools panel and enabling "Emulate a focused page" but I really want my extension to do it programmatically.
Why I want to do this :
Some websites don't behave the same when the page is not focused, so I want my extension to make their behavior consistent.
Do you think it is possible ? Thx :)
I've been searching online for a week now and I really can't find any solution to my problem...

Related

Copy to clipboard from website when browser is not focused

I wanted to create very small extension for website that will automatically copy some value to the clipboard.
The problem is that I want it to copy the value even if browser is not focused e.g.:
I open the website, my extension listens to the change on the page
I open different application
If something changes on the page then the extension should copy some value
Main application that I'm working with is still focused but I can CTRL+V paste value copied from the website without alt+tab
I tried to use Clipboard API:
navigator.clipboard.writeText(...)
but I don't think it will work because browser have to be focused(I think).
When page is focused then copying works fine. If I try to switch to different application I get an exception when my extension tries to copy the value:
DOMException: Document is not focused.
Is there any way to do this?
This is not possible for security reasons.. It's hard to imagine anyone wanting this behavior...
This document has a lot of good info..
In Chrome, you can request clipboard-write permissions to write to clipboard outside of a small user generated event, although it does not appear as though Chrome limits you to when you can write to clipboard.. According to the article below, you can write to the clipboard in Chrome from the background, etc.. See the note at the bottom of this section for more info.
If Chrome does allow you to write to clipboard from the background or if the window is not selected, you could possibly use the Page Visiblity API to kick off the copy event when "that" specific window is not visible.
You could possibly even use the window.addEventListener('blur', function(){...}) handler to test, etc...
All in all, this MAY be possible in Chrome, but it is definitely not supported in Firefox.
You can check out the differences between browsers and how they handle clipboard related events/permissions/etc, here..

how return focus on parent window using javascript?

is it possible return focus on tab parent using javascript?
I read some threads about this problem, but i didn't find solutions.
I tried
window.opener.parent.focus()
and
window.opener.focus();
but it doesn't work.
Can someone help me?
Thanks
Generally, you cannot do this inside a web page. Because it's the user's choice which tab/window she wants to focus on and browsers such as firefox and chrome respect such choices by providing configs to open new tabs in the background or not. But under several very special cases, you may still achieve this.
If you want to open a new tab and return focus immediately, you can try to simulate a 'ctrl+click' event on a link to open the tab on the background. Refer to this thread Open a new tab in the background?(Only for chrome, API may already changed. So it may only works on an obsoleted version)
If you are shipping with an extension, do it in the extension code. For example: in chrome extension.
If your script is for a customized browsers which you have control on / you can affect the design, you can implement the function in the browser side and expose an API for your script.

Liquid Slider not working properly in chrome extension

I am working on a google chrome extension. I am using Liquid slider to help me with the popup, when I am in brackets and do live preview, I get exactly the result I want.
https://gyazo.com/d2b5e7215ff8dfab59d677fd94637a25
But when I go into google chrome to test my extension this happens.
https://gyazo.com/48ea596645f0b16305915fb144d2aad8
It is not in the tab format anymore.
I could not find any support on this, if anyone has any idea why this does not work. Is it just because I can't use Liquid Slider in my chrome extension? I have no idea. Please tell me if you need more information.
Edit: If it is not possible to fix the error and bring back the tabs, we can also just use arrows, and figure out how to delete the tabs.
Chrome extensions have stricter security & sandboxing than regular web pages - for example, Content Security Policy is enabled by default. That may explain the difference.
To get more specifics about what's going wrong, you can debug your extension by right-clicking the icon and selecting Inspect Popup. This will open the familiar Chrome Dev Tools where you can check the console for errors, etc. Does that give you more specifics to go on?

Can I programmatically open the devtools from a Google Chrome extension?

I have a chrome extension which hooks into the devtools. Ideally I want a badge that, when clicked, opens up the devtools on the new tab which I created. Is there any way to do this from the background page?
It seems unlikely that this is possible or will ever become possible,
check this:
https://code.google.com/p/chromium/issues/detail?id=112277
which says:
"We only allow explicit devtools opening."
Yes you can (or not) using the experimental APIs chrome.experimental.webInspector.
http://code.google.com/chrome/extensions/experimental.html
You can even change the content and panels of it.
Note that you will not able submit extensions that use experimental APIs.
There is no way to do that.
The chrome://chromewebdata link only works if an instance of DevTools is already opened.
This is quite old but since I stumbled upon it now searching for a solution I figured others might have too. Since Chrome 28 you can use the devtools.* API. This allows you to open and manipulate DevTools panels. It is also notable no longer expirimental.
One could try
chrome.developerPrivate.openDevTools
Perhaps, the extension could kick off a Selenium script and you could use the "send_keys()" function as something like this:
ActionChains(driver).key_down(Keys.CONTROL).key_down(Keys.SHIFT).\
send_keys('J').key_up(Keys.CONTROL).key_up(Keys.SHIFT).perform()
... as "Ctrl+Shift+J" is the default keybind to open dev-tools (as of Jul 08, 2021)
It's not impossible with side extension, but if the reason is that you've tired to click Ctrl + Shift + I again and again every time - you can simply open the right button menu on needed page and select "Inspect" from it, it'll open the console like extension button, and also you don't need to search for its icon every time you need it, which is more conviniently than using an extension.

Open a chrome tab from delayed javascript window.open

When I window.open("http://blarg") in chrome, I get a new tab. If I delay the open, say using a jquery $(hrm).animate({},5e3,function(){window.open(url)); it opens the url in a new window with no status bar, etc — if I give it permission to pop-up that is.
I'm looking for a way to get the instant behavior, that is, I wish to open a URL after an animation, but still in a new tab.
I imagine I could get by with learning a way to instruct chrome to never ever open pop-ups and to always open them in tabs (I imagine there's a webkit setting, why it's not a built in is a mystery); but I'd rather try to find a way to do it from the javascript if possible.
I somewhat doubt there's any way to do this though. I'm not aware of any javascript that's tab-aware.
A similar question was asked about tabs in Firefox, but the same answer applies:
There is no way to force a window to open as a tab. It's all dependent on the user's preference settings.

Categories

Resources