我可以通过 Google Chrome 扩展程序以编程方式打开开发工具吗?

发布于 2024-11-26 01:25:27 字数 92 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

心意如水 2024-12-03 01:25:27

这似乎不太可能或将成为可能,

请检查以下内容:
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."

梦魇绽荼蘼 2024-12-03 01:25:27

是的,您可以(或不能)使用实验性 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.

爱情眠于流年 2024-12-03 01:25:27

没有办法做到这一点。

仅当已打开 DevTools 实例时,chrome://chromewebdata 链接才有效。

There is no way to do that.

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

没企图 2024-12-03 01:25:27

也许,扩展可以启动 Selenium 脚本,您可以使用“send_keys()”函数,如下所示:

ActionChains(driver).key_down(Keys.CONTROL).key_down(Keys.SHIFT).\
            send_keys('J').key_up(Keys.CONTROL).key_up(Keys.SHIFT).perform()

...因为“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:

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)

云仙小弟 2024-12-03 01:25:27

可以尝试

chrome.developerPrivate.openDevTools

One could try

chrome.developerPrivate.openDevTools

書生途 2024-12-03 01:25:27

我尝试制作一个模拟 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.

表情可笑 2024-12-03 01:25:27

侧面扩展并非不可能,但如果原因是您厌倦了每次一次又一次地单击 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.

谁对谁错谁最难过 2024-12-03 01:25:27

这是相当古老的,但自从我偶然发现它现在正在寻找解决方案时,我认为其他人也可能有。从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文