Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Google Chrome Remote Debugging Protocol in HTTP?

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?

like image 708
ajalab Avatar asked Feb 16 '26 13:02

ajalab


1 Answers

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');
    });
like image 74
nwinkler Avatar answered Feb 19 '26 02:02

nwinkler