从 JavaScript 以编程方式打开 Safari/Google Chrome 开发人员工具 [英] Open Safari / Google Chrome developer tools programmatically from JavaScript

查看:51
本文介绍了从 JavaScript 以编程方式打开 Safari/Google Chrome 开发人员工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种从附加到网页的脚本中打开 WebKit开发人员工具"的方法.我需要 Google Chrome 和 Safari 的解决方案,如果它尚未打开,它将打开开发人员工具窗格,并且(希望你能弄清楚如何)在打开时也切换到所述窗格的特定选项卡/部分.

I'm looking for a way to open the WebKit "developer tools" from a script attached to a web-page. I need solutions for both Google Chrome and Safari, that will open the developer-tools pane if it's not already open, and (hopefully, if you can figure out how) also switch to a particular tab/section of said pane upon opening.

(用例,如果有人感兴趣:如果出现错误并且开发人员正在查看页面,我想打开 console.log 输出窗口;此特定页面将是一些 JavaScript 单元测试的输出.)

(Use-case, if anyone's interested: I want to open the console.log output-window if there's been an error and a developer is looking at the page; this particular page will be the output of some JavaScript unit-tests.)

我在这个问题上悬赏,因为这显然是一个以前没有人满意地回答过的问题,而且答案是毛茸茸的.请不要回答它,除非您有一个真正的答案:1) 可以在两种浏览器中工作,并且 2) 不需要私有扩展 API从静态网页工作.

I'm setting a bounty on this question because it's obviously one that hasn't been answered to anyone's satisfaction before, and the answer is a hairy one. Please don't answer it unless you have a real answer that both: 1) works in both browsers, and 2) doesn't require private extension APIs that won't work from a static web-page.

请参阅(相关,但特定于 Chrome 和扩展程序):我可以从 Google Chrome 扩展程序以编程方式打开 devtools 吗?

See (related, but specific to Chrome, and extensions): Can I programmatically open the devtools from a Google Chrome extension?

推荐答案

简单地说:你不能.

开发工具不是沙盒的(与任何网页不同),因此授予沙盒环境打开和控制非沙盒环境的能力是一项主要安全设计缺陷.

The Dev Tools are not sandboxed (unlike any web page), thus granting sandboxed environments the power to open and control an unsandboxed environment is a major security design flaw.

我希望这能回答你的问题:-)

I hope this answers your question :-)

这篇关于从 JavaScript 以编程方式打开 Safari/Google Chrome 开发人员工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆