lucacasonato / deno-puppeteer

A port of puppeteer running on Deno
https://deno.land/x/puppeteer
MIT License
451 stars 40 forks source link

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

Open hwogrpw opened 2 years ago

hwogrpw commented 2 years ago

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: https://github.com/lucacasonato/deno-puppeteer/blob/f9678f578f0fc336a244763cba65291e309538be/src/deno/Launcher.ts#L53-L63

AlexJeffcott commented 10 months ago

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 https://github.com/denoland/deno/issues/16899#issue-1472707271 and https://github.com/microsoft/playwright/issues/3146#issuecomment-1273222406

// 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();
})();