Last active
April 26, 2024 21:54
-
-
Save bgrins/1dff754c66f319f440f3 to your computer and use it in GitHub Desktop.
Helpers that can be used when debugging Firefox in the Browser Console / Browser Debugger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Helpers that can be used when debugging Firefox in the Browser Console / Browser Debugger |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Get a reference to an existing toolbox for the currently | |
| selected tab */ | |
| var {devtools} = Cu.import("resource://devtools/shared/Loader.jsm", {}); | |
| var target = devtools.TargetFactory.forTab(gBrowser.selectedTab); | |
| var {gDevTools} = devtools.require("devtools/client/framework/devtools"); | |
| var toolbox = gDevTools.getToolbox(target); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function MyTool(iframeWindow, toolbox) { | |
| this.panelWin = iframeWindow; | |
| this._toolbox = toolbox; | |
| }; | |
| MyTool.prototype = { | |
| get target() this._toolbox.target, | |
| open: function() { | |
| console.log("Initializing things..."); | |
| return new Promise(resolve => { | |
| setTimeout(() => { | |
| console.log("Waited long enough.. open done"); | |
| resolve(this); | |
| }, 100); | |
| }); | |
| }, | |
| destroy: () => { | |
| console.log("Destroying things..."); | |
| } | |
| }; | |
| gDevTools.registerTool({ | |
| id: "mytool", | |
| label: "My Tool", | |
| build: (win, toolbox) => { | |
| return new MyTool(win, toolbox); | |
| }, | |
| isTargetSupported: () => { return true }, | |
| url: "data:text/html,<h1>My Tool</h1>" | |
| }) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Open a new toolbox (or reuse an existing one) for the | |
| currently selected tab */ | |
| var {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); | |
| var target = devtools.TargetFactory.forTab(gBrowser.selectedTab); | |
| gDevTools.showToolbox(target, "inspector", "window").then(toolbox=> { | |
| console.log(toolbox); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); | |
| var acorn = devtools.require("acorn/acorn"); | |
| var getToken = acorn.tokenize("var foo = 'bar'") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); | |
| var target = devtools.TargetFactory.forTab(gBrowser.selectedTab); | |
| var toolbox = gDevTools.getToolbox(target); | |
| var win = toolbox.doc.defaultView; | |
| var { addDebuggerToGlobal } = Cu.import("resource://gre/modules/jsdebugger.jsm", {}); | |
| addDebuggerToGlobal(this); | |
| var dbg = new Debugger(win); | |
| var path = ChromeUtils.saveHeapSnapshot({ debugger: dbg }); | |
| var snapshot = ChromeUtils.readHeapSnapshot(path); | |
| var census = snapshot.takeCensus({ breakdown: { by: "count", bytes: true } }); | |
| census; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment