I want to be able to run puppeteer-web from inside a chrome extension but have it connect to the browser using the chrome.debugger devtools API which is available to extensions. As opposed to connecting to the remote debugging port (9222) or websocket url.
The javascript code that is being run inside my extension is this:
const puppeteer = require('puppeteer');
async function runPuppet(url) {
const browser = await puppeteer.connect({browserURL: 'http://localhost:9222'});
const page = await browser.newPage();
await page.setRequestInterception(true);
await page.goto(url);
return page.url();
}
This works fine but it means that I have to start google chrome with the --remote-debugging-port=9222
option which is not ideal. It seems unecessary to open a remote debugging port when the chrome.debugger API is already available to extensions so the extension should not have to go "outside" of the application in order to access devtools.
I have seen that in the puppeteer browser test file there is an example where it calls puppeteer.connect({transport: window.cdp});
and that looks like the kind of thing that I want to do but the property window.cdp
is undefined in my extension and I can't find any documentation about it either.
Any help would be much appreciated, thanks.