4

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.

Evan Rolfe
  • 151
  • 1
  • 10
  • Hi Evan, did you end up finding a solution for this? I got around this using the target field as outlined https://stackoverflow.com/a/56457835/6261724 but it's not ideal. – tchan Oct 05 '19 at 08:35
  • No, unfortunately still no solution, though the target field solution is interesting, but yes I agree not ideal. Thanks – Evan Rolfe Oct 06 '19 at 09:17
  • Why don't you post a question on puppeteer github? https://github.com/GoogleChrome/puppeteer/issues/3455 – avalanche1 Oct 26 '19 at 16:08

0 Answers0