target option is broken: https://github.com/cyrus-and/chrome-remote-interface#cdpoptions-callback
const port = 52999;
const target = await CDP.New({ port });
console.log('target:', target);
/*
target: { description: '',
devtoolsFrontendUrl: '/devtools/inspector.html?ws=localhost:52999/devtools/page/5a5fabc4-1c6c-40c1-9181-81c56ac31707',
id: '5a5fabc4-1c6c-40c1-9181-81c56ac31707',
title: '',
type: 'page',
url: 'about:blank',
webSocketDebuggerUrl: 'ws://localhost:52999/devtools/page/5a5fabc4-1c6c-40c1-9181-81c56ac31707' }
*/
const client = await CDP({ target });
Produces the error:
{ Error: connect ECONNREFUSED 127.0.0.1:9222
at Object._errnoException (util.js:1019:11)
at _exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1175:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 9222 }
It seems the default port has precedence: https://github.com/cyrus-and/chrome-remote-interface/blob/master/lib/devtools.js#L103-L104
| Component | Version
|-|-
| Operating system | macOS / Ubuntu 16.04 / Docker
| Node.js | v8.6.0
| Chrome/Chromium/... | Chrome 61.0.3163.100
| chrome-remote-interface | 0.25.1
Is Chrome running in a container? I've tried both options.
Version 0.24.5 works as expected.
I cannot reproduce this using the latest release and the following:
const CDP = require('chrome-remote-interface');
async function test() {
const port = 52999;
const target = await CDP.New({ port });
console.log('target:', target);
const client = await CDP({ target });
console.log(await client.Runtime.evaluate({expression: `'it works'`}));
client.close();
}
test();
I obtain:
$ node issue-279.js
target: { description: '',
devtoolsFrontendUrl: '/devtools/inspector.html?ws=localhost:52999/devtools/page/6b6085bd-5797-4f5b-a783-e3d46160e011',
id: '6b6085bd-5797-4f5b-a783-e3d46160e011',
title: '',
type: 'page',
url: 'about:blank',
webSocketDebuggerUrl: 'ws://localhost:52999/devtools/page/6b6085bd-5797-4f5b-a783-e3d46160e011' }
{ result: { type: 'string', value: 'it works' } }
Chrome is started with:
google-chrome --headless --remote-debugging-port=52999 --disable-gpu
Updated testcase:
const chromeLauncher = require('chrome-launcher');
const CDP = require('chrome-remote-interface');
async function test() {
const chrome = await chromeLauncher.launch({
handleSIGINT: false,
chromeFlags: [
'--headless',
'--disable-gpu',
],
});
const target = await CDP.New({ port: chrome.port });
console.log('target:', target);
const client = await CDP({ target });
console.log(await client.Runtime.evaluate({expression: `'it works'`}));
client.close();
}
test();
0.24.5 - works
0.25.1 - does not
Hmm, it still works here...
$ node issue-279.js
target: { description: '',
devtoolsFrontendUrl: '/devtools/inspector.html?ws=localhost:34719/devtools/page/5f5a642e-b6a8-477a-bd19-fa0e0c5f5b3a',
id: '5f5a642e-b6a8-477a-bd19-fa0e0c5f5b3a',
title: '',
type: 'page',
url: 'about:blank',
webSocketDebuggerUrl: 'ws://localhost:34719/devtools/page/5f5a642e-b6a8-477a-bd19-fa0e0c5f5b3a' }
{ result: { type: 'string', value: 'it works' } }
The only difference is that Node.js doesn't exit now.
I'm running Debian 9.
I've tried on macOS/Crome 61.0.3163.100 and the following Docker container:
FROM node:8
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update && apt-get install -y --no-install-recommends \
google-chrome-stable \
&& rm -rf /var/lib/apt/lists/*
Both with [email protected]
Wow, I apologize, I had a running background Chrome instance on port 9222... :/
I'm going to fix this, in the meanwhile just pass the port in addition to the target, like this:
const client = await CDP({ target , port: chrome.port });
Alright, it should work now; I will bump a new version once you confirm.
Bumped: v0.25.2.
Hi @cyrus-and Sorry for the delay. Thank you it works as expected 馃憤
Most helpful comment
Wow, I apologize, I had a running background Chrome instance on port 9222... :/
I'm going to fix this, in the meanwhile just pass the port in addition to the target, like this: