lucacasonato / deno-puppeteer

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

TypeError: reader is not async iterable at getReadableStreamAsUint8Array #73

Open mflisikowski opened 1 year ago

mflisikowski commented 1 year ago

Deno info:

🐉 >deno info
DENO_DIR location: /Users/mateuszflisikowski/Library/Caches/deno
Remote modules cache: /Users/mateuszflisikowski/Library/Caches/deno/deps
npm modules cache: /Users/mateuszflisikowski/Library/Caches/deno/npm
Emitted modules cache: /Users/mateuszflisikowski/Library/Caches/deno/gen
Language server registries cache: /Users/mateuszflisikowski/Library/Caches/deno/registries
Origin storage: /Users/mateuszflisikowski/Library/Caches/deno/location_data

TypeError: reader is not async iterable

TypeError: reader is not async iterable
    at getReadableStreamAsUint8Array (https://deno.land/x/puppeteer@16.2.0/vendor/puppeteer-core/puppeteer/common/util.js:329:29)
    at Page.pdf (https://deno.land/x/puppeteer@16.2.0/vendor/puppeteer-core/puppeteer/common/Page.js:2606:24)
    at async Server.<anonymous> (file:///home/deno/functions/download-cv/index.ts:21:17)
    at async Server.#respond (https://deno.land/std@0.131.0/http/server.ts:298:18)

Supabase function code, that try to run.

import puppeteer from 'https://deno.land/x/puppeteer@16.2.0/mod.ts';
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';

serve(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  await page.goto('https://mflisikowski.dev/cv', {
    waitUntil: 'networkidle2',
  });

  const pdf = await page.pdf({ format: 'A4' });

  await browser.close();

  return new Response(pdf, {
    headers: {
      'Content-Disposition': `attachment; filename="cv.pdf"`,
      'Content-Type': 'application/pdf',
    },
  });
});
danilopolani commented 1 year ago

Same here, same as #67
Probably it's worth waiting for https://github.com/denoland/deno/issues/18913 so we can use Puppeteer from npm and have it always updated

PhilippS93 commented 1 year ago

I also have the same problem using Superbase edge functions and browserless

drobles-atdev commented 12 months ago

any updates on solving this issue?

julianolm commented 12 months ago

Im also running into this error after calling page.pdf on a supabase edge function. Would love to get updates

vinch commented 3 months ago

Was anyone able to solve this problem? I run into the same issue with Supabase Edge Functions.

julianolm commented 3 months ago

@vinch in my use case I could solve the issue by replacing my puppeteer.launch() call with a puppeteer.connect(...) instead. For that I had to launch a browserless io instance and connect puppeteer with it. Check browserless.io solution here.

Basically my code changed from

const browser = await puppeteer.launch();
const page = await browser.newPage();

to

const browser = await puppeteer.connect({
    browserWSEndpoint: `wss://chrome.browserless.io?token=${Deno.env.get("PUPPETEER_BROWSERLESS_IO_KEY")}`,
});
const page = await browser.newPage();

I dont know if that is actually an overkill, but I could solve my problem and the solution was very easy.

ps: Launching browserless instance was super easy (and for my usecase it was free)

vinch commented 3 months ago

@julianolm Yeah that's what I did as well but I didn't use Browserless (too expensive for me) but instead ran my own Puppeteer instance on DigitalOcean.

julianolm commented 3 months ago

@vinch nailed it! Congrats

pasha-bolokhov commented 2 months ago

I was able to use Puppeteer directly from NPM using the following:

import * as Puppeteer from "npm:puppeteer";

const url = "https://example.com";

const BROWSER_PATH = "<path-to-chrome>/chrome";

const browser = await Puppeteer.launch({ headless: true, executablePath: BROWSER_PATH });

const page = await browser.newPage();

await page.goto(url, { waitUntil: "networkidle2" });

const pdf = await page.pdf({ format: "letter" });

await Deno.writeFile("output.pdf", pdf);

await page.screenshot({ path: "output.png" });

await browser.close();

It does produce a warning:

Warning: Not implemented: ClientRequest.options.createConnection

but, despite it, it does complete

Don't know how critical the warning is?