3

I referred http://code.google.com/chrome/devtools/docs/remote-debugging.html.

First, I started a new chrome process.

chrome --remote-debugging-port=9222 --user-data-dir=remote-profile

Then I want to try some options written in http://code.google.com/intl/ja/chrome/devtools/docs/protocol/tot/index.html, but how can I use them? I already know how to use those methods in WebSocket, but I have to use it in HTTP.

I tried this nodejs code but failed.

var http = require('http');
var options = {
 host: 'localhost',
 port: 9222,
 path: '/devtools/page/0',
 method: 'POST'
};
var req = http.request(options, function (res) {
 console.log(res.headers);
 res.on('data', function (chunk) {
 console.log(chunk);
 });
});
req.on('error', function (e) { console.log('problem' + e.message); });
req.write(JSON.stringify({
 'id': 1,
 'method': "Page.enable"
}));
req.end();

Is it wrong?

nwinkler
54.9k23 gold badges166 silver badges170 bronze badges
asked Oct 21, 2011 at 11:41

3 Answers 3

4

I know this is a fairly old question, but I ran into it when I was trying to do something similar.

There's an npm module called chrome-remote-interface, which makes using the Chrome Remote Debugging API a lot easier: https://github.com/cyrus-and/chrome-remote-interface

npm install chrome-remote-interface

Then you can use the module in your code like this:

 var Chrome = require('chrome-remote-interface');
 Chrome(function (chrome) {
 with (chrome) {
 on('Network.requestWillBeSent', function (message) {
 console.log(message.request.url);
 });
 on('Page.loadEventFired', close);
 Network.enable();
 Page.enable();
 Page.navigate({'url': 'https://github.com'});
 }
 }).on('error', function () {
 console.error('Cannot connect to Chrome');
 });
answered Jan 7, 2014 at 11:53
Sign up to request clarification or add additional context in comments.

1 Comment

is there any way I can save message.request.url in a variable?
0

I think it says "Note that we are currently working on exposing an HTTP-based protocol that does not require client WebSocket implementation."

I'm not sure it means that you can have HTTP instead of WebSocket now.

answered Oct 22, 2011 at 16:15

Comments

0

There is also a fantastic NPM module called Weinre that allows you to easily use the Chrome debugging/ remote debugging tools. If you have to test cross browser too it allows you to use the Chrome tools even on certain versions of IE. There is some more information on the MSDN blog.

Qantas 94 Heavy
16k31 gold badges73 silver badges89 bronze badges
answered Jan 24, 2014 at 22:26

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.