Closed Tin-Nguyen closed 7 years ago
It seems it's related to the issue on chrome-remote-interface
component https://github.com/cyrus-and/chrome-remote-interface/issues/213
Under what context does that happens?
It works well locally, however, it shows the error on server with
OS: AWS Linux
Running Chrome via Docker
can you help to check the issue @LucianoGanga ?
It works well with my local Docker Chrome, but it doesn't work on the Docker Chrome on server. Any advises to fix it?
I resolved the issue, the root cause is explained at https://github.com/cyrus-and/chrome-remote-interface/issues/213#issuecomment-335517254.
I changed the source code to only connect to the remote chrome instance once time when starting the server, it resolved my issue. Close the issue now
@Tin-Nguyen I hit the Error, but how to ensure only one remote chrome instance. like this?
const CDPGlobal = {
client: null,
getClient: async () => {
if (this.client) {
return this.client;
} else {
const {host, port, } = setting;
const chromeParams = {
host,
port,
};
this.client = await CDP(chromeParams);
const {Network, Page, Runtime} = client;
await Page.enable();
await Runtime.enable();
await Network.enable();
await Network.setCacheDisabled({cacheDisabled: true});
return this.client;
}
},
close: async () => {
if (this.client) {
this.client = null;
await this.client.close();
}
}
}
let html = '';
try {
const client = await CDPGlobal.getClient();
const {Page,} = client;
await Page.navigate({url});
await Page.loadEventFired();
const result = await Runtime.evaluate({
expression: 'document.documentElement.outerHTML'
});
html = result.result.value;
}
} catch (err) {
console.error(err);
await CDPGlobal.close();
} finally {
console.log(html);
}
I'm facing the issue sometimes on my API using
simple-headless-chrome
Can someone help to check?