Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Debugger.getScriptSource' method is not working #7

Closed
lifeasageek opened this issue Feb 9, 2014 · 1 comment
Closed

'Debugger.getScriptSource' method is not working #7

lifeasageek opened this issue Feb 9, 2014 · 1 comment

Comments

@lifeasageek
Copy link

While the event "Debugger.scriptParsed" is correctly handled, getScriptSource() always returns "undefined" value.

I guess I was invoking the method (getScriptSource()) in a wrong way as inspector.js of blink is calling the getScriptSource() via DebuggerAgent, which seems to be the wrapper of Debugger interface.


var spawn=require('child_process').spawn;
var Chrome = require('chrome-remote-interface');
var initWaitTime = 2000;
var ChromePath = "/usr/bin/chromium-browser";

function runChrome(extensionDir) {
var args = [];
args.push("--remote-debugging-port=9222");
args.push("--user-data-dir=remote-profile");
args.push("-no-default-browser-check");
spawn(ChromePath, args)
};

function runChromeDebugger(urlToVisit) {
console.log("runChromeDebugger");
options = {};
Chrome(options, function (chrome) {
with (chrome) {
on('Debugger.scriptParsed', function (msg) {
console.log("==================================");
console.log(JSON.stringify(msg));
console.log("scriptParsed scriptId: " + msg.scriptId); // scriptId is correctly returned
var ssrc = chrome.Debugger.getScriptSource({'scriptId':msg.scriptId});
console.log("scriptSource :" + ssrc); // bug? always undefined
});
Page.enable();
Debugger.enable();
Page.navigate({'url': urlToVisit});
console.log("[*] opened [" + urlToVisit + "]");
}
}).on('error', function () {
console.error('Cannot connect to Chrome');
});
}

if (require.main == module) {
runChrome("/home/blee/project/chrome-extension-integrity/sample/buzzdoc");
var urlToVisit = "http://google.com"
setTimeout(function() {runChromeDebugger(urlToVisit)}, initWaitTime);
}

@lifeasageek
Copy link
Author

Oh.. I figured this out. Gotta get the results back using the callback function like below. Thanks for the great code!

        on('Debugger.scriptParsed', function (msg) {
            chrome.Debugger.getScriptSource(
                {'scriptId':msg.scriptId},
                function (err, msg) {
                    if (err) return;
                    console.log("script : " + JSON.stringify(msg));
                });
        });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants