I referred .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 .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?
I referred http://code.google./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./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?
Share Improve this question edited Jan 7, 2014 at 11:54 nwinkler 54.6k23 gold badges164 silver badges170 bronze badges asked Oct 21, 2011 at 11:41 ajalabajalab 311 silver badge2 bronze badges3 Answers
Reset to default 4I 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./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.'});
}
}).on('error', function () {
console.error('Cannot connect to Chrome');
});
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.
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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745339347a4623252.html
评论列表(0条)