lucacasonato/deno-puppeteer

Missing `pipe` option in `puppeteer.launch([options])`

hwogrpw opened this issue · 1 comments

When the following code is ran, a WebSocket connection to the browser is established.

const browser = await puppeteer.launch({pipe: true});

But according to puppeteer.launch, a pipe should be used instead:

pipe <boolean> Connects to the browser over a pipe instead of a WebSocket. Defaults to false.

Seems the code doesn't care about the pipe option:

const {
ignoreDefaultArgs = false,
args = [],
executablePath = null,
env = Deno.env.toObject(),
ignoreHTTPSErrors = false,
defaultViewport = { width: 800, height: 600 },
slowMo = 0,
timeout = 30000,
dumpio = false,
} = options;

This is likely because the pipe option does not work in Deno which makes the compatibility claim in https://deno.com/blog/v1.35 a little confusing.

Assuming you have “installed” a browser with deno run -q --no-lock -A --unstable --no-check --reload npm:puppeteer/install.mjs, the following code works with deno run -A index.mjs (it does have a “Warning: Not implemented: ClientRequest.options.createConnection”, though).

// index.mjs
import puppeteer from 'npm:puppeteer'

(async () => {
  const browser = await puppeteer.launch({
    headless: 'new',
    pipe: false
  });
  const page = await browser.newPage();
  await page.goto('https://developer.chrome.com/');
  await page.setViewport({width: 1920, height: 1080});
  await page.screenshot({path: './test.jpg'})
  await browser.close();
  Deno.exit(1)
})();

But with pipe: true it breaks with the same deno run -A index.mjs command.
Here is the output: error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'on').

You can find the same issue with regards to Playwright support. See denoland/deno#16899 (comment) and microsoft/playwright#3146 (comment)

// index.mjs
import puppeteer from 'npm:puppeteer'

(async () => {
  const browser = await puppeteer.launch({
    headless: 'new',
    pipe: true
  });
  const page = await browser.newPage();
  await page.goto('https://developer.chrome.com/');
  await page.setViewport({width: 1920, height: 1080});
  await page.screenshot({path: './test.jpg'})
  await browser.close();
  Deno.exit(1)
})();

Here is the same in Node (assuming that you have installed Puppeteer with npm i puppeteer which works just fine with the pipe option by running node index.mjs.

// index.mjs
import puppeteer from 'puppeteer'

(async () => {
  const browser = await puppeteer.launch({
      headless: 'new',
      pipe: true
  });
  const page = await browser.newPage();
  
  await page.goto('https://developer.chrome.com/');
  await page.setViewport({width: 1920, height: 1080});
  await page.screenshot({path: './test.jpg'})
  await browser.close();
})();