Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在HTTP中使用Google Chrome远程调试协议?_Javascript_Node.js_Google Chrome Devtools - Fatal编程技术网

Javascript 如何在HTTP中使用Google Chrome远程调试协议?

Javascript 如何在HTTP中使用Google Chrome远程调试协议?,javascript,node.js,google-chrome-devtools,Javascript,Node.js,Google Chrome Devtools,我提到过 首先,我开始了一个新的铬工艺 chrome --remote-debugging-port=9222 --user-data-dir=remote-profile 然后我想尝试一些写在中的选项,但是我如何使用它们呢? 我已经知道如何在WebSocket中使用这些方法,但我必须在HTTP中使用它 我尝试了这个nodejs代码,但失败了 var http = require('http'); var options = { host: 'localhost', port: 92

我提到过

首先,我开始了一个新的铬工艺

chrome --remote-debugging-port=9222 --user-data-dir=remote-profile
然后我想尝试一些写在中的选项,但是我如何使用它们呢? 我已经知道如何在WebSocket中使用这些方法,但我必须在HTTP中使用它

我尝试了这个nodejs代码,但失败了

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();
它错了吗?

我认为它说的是“注意,我们目前正在公开一个不需要客户端WebSocket实现的基于HTTP的协议。”


我不确定这是否意味着现在可以使用HTTP而不是WebSocket。

我知道这是一个相当老的问题,但我在尝试做类似的事情时遇到了这个问题

有一个名为
chrome remote interface
的npm模块,它使chrome远程调试API的使用更加容易:

然后,您可以在代码中使用以下模块:

    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');
    });

还有一个很棒的名为Weinre的NPM模块,允许您轻松使用Chrome调试/远程调试工具。如果您也必须测试跨浏览器,它允许您在IE的某些版本上使用Chrome工具。还有更多信息。

有没有办法将
message.request.url
保存在变量中?
    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');
    });