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

8

117

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?

Downy answered 23/7, 2011 at 15:58 Comment(5)
where you able to find an answer to the problem?Buckles
This would still be really nice wouldn't it - any updates?Ochoa
I've posted (and will be adding a bounty to) a related, but slightly different, question here: #16660825Plasterwork
See: #36311691Mortmain
In case you're curious like me what Chrome uses itself to open the devtools when you click the "backgroung page" link on an extension page, it's chrome.developerPrivate.openDevTools()Squire
C
36

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."

Chapple answered 13/6, 2013 at 8:10 Comment(2)
Indeed they recently re-confirmed the decision to not allow programmatic opening of the dev tools.Jean
see also bugs.chromium.org/p/chromium/issues/detail?id=445240Harakiri
Y
8

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.

Yours answered 25/7, 2011 at 21:37 Comment(3)
However, it's worth noting that you can host these outside of the extensions gallery if you are determined. Although this would mean that users would also have to use the dev channel and enable the Experimental Extension APIs flag.Albumenize
experimental.webInspector is now called chrome.experimental.devtools. Some of the APIs are not experimental any more, and they are listed under chrome.devtools. Unfortunately, there is no way to automatically open the Dev tools via a Chrome extension.Tarim
@Rob W, Didn't notice chrome.devtools.* APIs have become outside of experiment APIs.Negligent
A
5

There is no way to do that.

The chrome://chromewebdata link only works if an instance of DevTools is already opened.

Altamirano answered 23/7, 2011 at 16:3 Comment(0)
W
1

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.

Wryneck answered 28/3, 2019 at 1:3 Comment(3)
Do you remember what method is used to progammatically open the devtools from the background script? All other answers (from stackoverflow) seem to suggest that it's impossible...Alleviate
@Sentero-esp12 just click right button on needed page and select "Inspect" from it)Clance
This doesn't answer the question. The devtools.* APIs are for building extensions to the developer tools. They don't provide a way to launch it programatically. And the question was how to do it programmatically, so "just click right" isn't an answer.Cappella
T
1

One could try

chrome.developerPrivate.openDevTools

Trichiasis answered 18/6, 2020 at 9:44 Comment(0)
K
1

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)

Kantian answered 8/7, 2021 at 12:50 Comment(2)
Could provide more details on this and how to use these scripts?Geodesy
@Geodesy sure thing, sorry for the wait just saw this; selenium-python.readthedocs.io/index.htmlKantian
B
1

I tried to make a script that simulates a CRTL+ALT+J which opens the devtools but it didn't work. After that I found this: It is not possible due to security restrictions. Browsers do not allow scripts to programmatically open the console or trigger certain keyboard shortcuts for security reasons. These restrictions are in place to prevent malicious activities. If you need to interact with the console, you can do that only manually, or use the browser's developer tools.

Bothy answered 5/1 at 22:5 Comment(0)
C
0

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.

Clance answered 29/7, 2020 at 23:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.