Debugging frame scripts 编辑

The Browser Content Toolbox is only available if you're running Firefox in multiprocess mode.

You can use the Browser Content Toolbox to debug frame scripts. The Browser Content Toolbox is a separate window that includes some of the standard Firefox Developer Tools - specifically: the console, the JavaScript debugger, and Scratchpad - but attaches them to the browser's content process. This means you can debug the frame scripts in your add-on.

Opening the Browser Content Toolbox

To open the Browser Content Toolbox, you'll need to:

You should now see an item labeled "Browser Content Toolbox" in the Developer submenu in the Firefox Menu (or Tools menu if you display the menu bar or are on OS X). It opens in a separate window:

If you've used the Firefox Developer Tools before, this should look pretty familiar.

Along the top is a row of tabs that you can use to switch the active tool. Currently, we only support the Console, the Debugger, and Scratchpad in the Browser Content Toolbox. At the right of this row are three buttons that activate the split console, open settings, and close the toolbox.

The rest of the toolbox is taken up with the tool you've currently selected.

Usage

The Debugger

The Debugger lists all the scripts that are loaded into the content process. You'll find your frame scripts listed under the chrome:// URL you registered for them:

You can set breakpoints, of course, and do all the other things supported by the debugger.

The Console

The Console logs output from your frame scripts. You can access an array of globals for each tab in the content process using the tabs getter e.g. to get the nodePrincipal of an element in the first-opened tab of the content process: tabs[0].content.document.querySelector("#myEl").nodePrincipal

If you want to use it to evaluate JavaScript in your frame script's scope, there's a trick you need to know:

  • Set a breakpoint in your frame script.
  • When you hit the breakpoint, switch to the Console, or activate the split console by pressing "Escape".

Now the console's scope is your frame script's scope, and you can interact directly with it:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:83 次

字数:4467

最后编辑:7 年前

编辑次数:0 次

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