Skip to content

Instantly share code, notes, and snippets.

@past
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save past/d92f80f147c06bfacf9c to your computer and use it in GitHub Desktop.

Select an option

Save past/d92f80f147c06bfacf9c to your computer and use it in GitHub Desktop.

Revisions

  1. past revised this gist May 15, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions list-resources.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    // -sp-context:browser
    // Open this file in scratchpad and run it. Output goes to the Browser Console (Cmd-Shift-J).

    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", {});
  2. past created this gist May 15, 2014.
    63 changes: 63 additions & 0 deletions list-resources.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    // -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;
    console.log("HTML:", tab.url);
    // 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();