-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get remote webSocketDebuggerUrl (or connect without GUID) #940
Comments
As to your second question: |
Thanks @kdekooter, I've put together the below script which is working (I'm new to node so feel free to comment on my appalling structure and handling of async): generate.js/*
* A puppeteer script to generate a PDF from stdin using a remote chrome instance.
* The generated PDF content is returned to stdout.
*
* Usage: node generate.js <host:port> <format>
*/
'use strict';
const puppeteer = require('puppeteer');
const http = require('http');
var html = '';
var endpoint = process.argv[2];
var format = process.argv[3] ? process.argv[3] : 'A4';
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
const chunk = process.stdin.read();
if (chunk !== null) {
html += chunk;
}
});
process.stdin.on('end', () => {
http.get(`http://${process.argv[2]}/json/version`, (res) => {
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => { rawData += chunk; });
res.on('end', () => {
try {
const parsedData = JSON.parse(rawData);
endpoint = parsedData.webSocketDebuggerUrl;
(async () => {
const browser = await puppeteer.connect({browserWSEndpoint: endpoint});
const page = await browser.newPage();
await page.setJavaScriptEnabled(false);
await page.goto(`data:text/html,${html}`, {waitUntil: 'networkidle'});
const pdf = await page.pdf({format: format});
await process.stdout.write(pdf);
await browser.close();
})();
} catch (e) {
console.error(`Unable to generate PDF: ${e.message}`);
}
});
}).on('error', (e) => {
console.error(`Unable to connect to Chrome: ${e.message}`);
});
}); For example: If anyone has any suggestions to speed this up and/or avoid the |
@davidwindell why do you want to avoid this? Since you're the one who starts chrome, you can get its GUID and share with all interested parties. |
@aslushnikov we launch the chrome instance automatically in a disposable docker container and communicating/broadcasting the Guid just wouldn't work. A reboot of the host means all dependent services have to look it up. |
@davidwindell I see, thanks. This seems to be a general service discovery problem, but yes, you |
@davidwindell , @kdekooter
I'm starting my headless-chrome instance using these flags:
Am I missing any step to detect the |
@drorweissweiss this is only in the latest versions of Chrome (62+ I think, certainly 63). Caught me out at first! |
FYI: In Chrome 65+ (maybe earlier) there is a |
@aslushnikov for the new version Possible WayIs there a way to start chromium with a custom GUID so that my Thanks |
@ja8zyjits did you find any solution to the dynamic guid when deploying multiple chrome instances? |
@ginuerzh i would also be interested to understand the same! |
Does anyone have the solution of this question? |
It is in /json/list |
We're using
puppeteer.connect
to connect to a remote Chrome instance:Is there any way we can avoid needing to know the GUID? Perhaps by a flag when starting the remote Chrome (it's on a secure internal network).
Alternatively, what would be the best way in node to look up the
browserWSEndpoint
fromhttp://{remoteip}:9222/json/version
?Or are we approaching this the wrong way?
The text was updated successfully, but these errors were encountered: