我可以通过 Google Chrome 扩展程序以编程方式打开开发工具吗?
我有一个 chrome 扩展,可以连接到开发工具中。理想情况下,我想要一个徽章,当单击该徽章时,会在我创建的新选项卡上打开开发工具。有什么办法可以从后台页面执行此操作吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
这似乎不太可能或将成为可能,
请检查以下内容:
https://code.google.com/p/chromium/issues/detail?id=112277< /a>
上面写着:
“我们只允许显式打开开发工具。”
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."
是的,您可以(或不能)使用实验性 API
chrome.experimental.webInspector
。http://code.google.com/chrome/extensions/experimental.html
您甚至可以更改它的内容和面板。
请注意,您将无法提交使用实验性 API 的扩展。
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.
没有办法做到这一点。
仅当已打开 DevTools 实例时,
chrome://chromewebdata
链接才有效。There is no way to do that.
The
chrome://chromewebdata
link only works if an instance of DevTools is already opened.也许,扩展可以启动 Selenium 脚本,您可以使用“send_keys()”函数,如下所示:
...因为“Ctrl+Shift+J”是打开开发工具的默认按键绑定(截至 7 月) 2021 年 08 月)
Perhaps, the extension could kick off a Selenium script and you could use the "send_keys()" function as something like this:
... as "Ctrl+Shift+J" is the default keybind to open dev-tools (as of Jul 08, 2021)
可以尝试
chrome.developerPrivate.openDevTools
One could try
chrome.developerPrivate.openDevTools
我尝试制作一个模拟
CRTL+ALT+J
的脚本来打开开发工具,但它不起作用。之后我发现了这个:由于安全限制,这是不可能的。出于安全原因,浏览器不允许脚本以编程方式打开控制台或触发某些键盘快捷键。这些限制是为了防止恶意活动。
如果您需要与控制台交互,则只能手动执行,或使用浏览器的开发人员工具。
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.
侧面扩展并非不可能,但如果原因是您厌倦了每次一次又一次地单击 Ctrl + Shift + I - 您只需打开所需页面上的右键菜单并从中选择“检查”,它就可以了。会像扩展按钮一样打开控制台,而且你不需要每次需要时都搜索它的图标,这比使用扩展更方便。
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.
这是相当古老的,但自从我偶然发现它现在正在寻找解决方案时,我认为其他人也可能有。从 Chrome 28 开始,您可以使用 devtools.* API。这允许您打开和操作 DevTools 面板。值得注意的是,它不再是实验性的。
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.