Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: reader is not async iterable at getReadableStreamAsUint8Array #73

Open
mflisikowski opened this issue Dec 27, 2022 · 9 comments

Comments

@mflisikowski
Copy link

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/[email protected]/vendor/puppeteer-core/puppeteer/common/util.js:329:29)
    at Page.pdf (https://deno.land/x/[email protected]/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/[email protected]/http/server.ts:298:18)

Supabase function code, that try to run.

import puppeteer from 'https://deno.land/x/[email protected]/mod.ts';
import { serve } from 'https://deno.land/[email protected]/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
Copy link

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

@PhilippS93
Copy link

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

@drobles-atdev
Copy link

any updates on solving this issue?

@julianolm
Copy link

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

@vinch
Copy link

vinch commented Jun 19, 2024

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

@julianolm
Copy link

julianolm commented Jun 19, 2024

@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
Copy link

vinch commented Jun 19, 2024

@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
Copy link

@vinch nailed it! Congrats

@pasha-bolokhov
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants