Reputation:
I am using puppeteer to launch a new Chrome browser window:
const util = require('util');
const puppeteer = require('puppeteer');
(async () => {
const b = await puppeteer.launch({
headless: false,
devtools: true, // open DevTools when window launches
args: ['--remote-debugging-port=9222']
});
console.log('browser:', util.inspect(b));
const c = await puppeteer.connect({
browserWSEndpoint: b._connection._url, //`ws://${host}:${port}/devtools/browser/<id>`,
ignoreHTTPSErrors: false
});
console.log('connection =>', c);
})();
my question is - how can I use the websocket connection c
, to send DevTools protocol messages to the browser window? I'd like to open a new tab, and do some other actions. Anybody know how?
Upvotes: 2
Views: 3162
Reputation: 1522
Haven't tested it but reading from the documentation you could do something like this:
const client = await page.target().createCDPSession();
await client.send('Target.createTarget', {'https://stackoverflow.com'});
You can find the:
Upvotes: 4