Created
May 15, 2014 10:26
-
-
Save past/7d3908cb695aaca3f276 to your computer and use it in GitHub Desktop.
This file contains 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
// -sp-context:browser | |
Components.utils.import("resource://gre/modules/devtools/dbg-server.jsm"); | |
Components.utils.import("resource://gre/modules/devtools/dbg-client.jsm"); | |
let { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); | |
let { StyleSheetsFront } = devtools.require("devtools/server/actors/stylesheets"); | |
let client; | |
function startDebugger() | |
{ | |
// Start the server. | |
if (!DebuggerServer.initialized) { | |
DebuggerServer.init(); | |
DebuggerServer.addBrowserActors(); | |
} | |
// Listen to an nsIPipe | |
let transport = DebuggerServer.connectPipe(); | |
// Start the client. | |
client = new DebuggerClient(transport); | |
client.connect(onConnected); | |
} | |
function shutdownDebugger() | |
{ | |
client.close(); | |
} | |
/** | |
* Start debugging the current tab. | |
*/ | |
function onConnected() | |
{ | |
// Get the list of tabs to find the one to attach to. | |
client.listTabs(function(response) { | |
// Find the active tab. | |
let tab = response.tabs[response.selected]; | |
// Attach to the tab. | |
client.attachTab(tab.actor, function(response, tabClient) { | |
if (!tabClient) return; | |
// Attach to the thread (context). | |
client.attachThread(response.threadActor, function(response, threadClient) { | |
if (!threadClient) return; | |
// Fetch the JS sources. | |
threadClient.getSources(function(response) { | |
console.log("JS:", response.sources.map(s => s.url)); | |
// Fetch the stylesheets. | |
let ssf = StyleSheetsFront(client, tab); | |
ssf.getStyleSheets().then((styleSheets) => { | |
console.log("CSS:", styleSheets.map(s => s.href)); | |
}); | |
}); | |
// Resume the thread. | |
threadClient.resume(); | |
// Debugger is now ready and debuggee is running. | |
}); | |
}); | |
}); | |
} | |
startDebugger(); | |
// shutdownDebugger(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment