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

deno fails to run puppeteer #25528

Closed
begoon opened this issue Sep 9, 2024 · 3 comments · Fixed by #25555
Closed

deno fails to run puppeteer #25528

begoon opened this issue Sep 9, 2024 · 3 comments · Fixed by #25555
Assignees
Labels
bug Something isn't working correctly node compat

Comments

@begoon
Copy link

begoon commented Sep 9, 2024

Version: Deno 1.46.3

index.ts:

import puppeteer from "puppeteer";

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://jsr.io");
await page.pdf({ path: "example.pdf", format: "A4" });

await browser.close();

package.json:

{ "dependencies": { "puppeteer": "^23.3.0" } }
deno run -A index.ts
Warning: Not implemented: ClientRequest.options.createConnection
error: Uncaught (in promise) TypeError: fileHandle.writeFile is not a function
    at getReadableAsTypedArray (file:///Users/alexander/github/tmpz/puppeteer/node_modules/.deno/[email protected]/node_modules/puppeteer-core/lib/esm/puppeteer/common/util.js:154:34)
    at eventLoopTick (ext:core/01_core.js:214:9)
    at async CdpPage.pdf (file:///Users/alexander/github/tmpz/puppeteer/node_modules/.deno/[email protected]/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/Page.js:825:28)
    at async file:///Users/alexander/github/tmpz/puppeteer/index.ts:6:1

However:

bun index.ts

works.

@kt3k kt3k added bug Something isn't working correctly node compat labels Sep 10, 2024
@kt3k
Copy link
Member

kt3k commented Sep 10, 2024

Looks like FileHandle class misses writeFile method (and also many others such as appendFile, chmod, chown, createReadStream, etc), and that causes the above error.

export class FileHandle extends EventEmitter {

I'll work on this issue.

(Note: missing FileHandle methods are tracked in #25554 )

@nitasn
Copy link

nitasn commented Dec 11, 2024

Same here (macOS M1), though I got a different error.

import puppeteer from "npm:puppeteer";
await puppeteer.launch();
$ deno -A code.ts
error: Uncaught (in promise) Error: Could not find Chrome (ver. 131.0.6778.87). This can occur if either
 1. you did not perform an installation before running the script (e.g. `npx puppeteer browsers install chrome`) or
 2. your cache path is incorrectly configured (which is: /Users/nitsan/.cache/puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
    at ChromeLauncher.resolveExecutablePath (file:///Users/nitsan/Library/Caches/deno/npm/registry.npmjs.org/puppeteer-core/23.10.3/lib/esm/puppeteer/node/BrowserLauncher.js:266:27)
    at ChromeLauncher.computeLaunchArguments (file:///Users/nitsan/Library/Caches/deno/npm/registry.npmjs.org/puppeteer-core/23.10.3/lib/esm/puppeteer/node/ChromeLauncher.js:85:24)
    at eventLoopTick (ext:core/01_core.js:175:7)
    at async ChromeLauncher.launch (file:///Users/nitsan/Library/Caches/deno/npm/registry.npmjs.org/puppeteer-core/23.10.3/lib/esm/puppeteer/node/BrowserLauncher.js:45:28)
    at async file:///Users/nitsan/Desktop/fun/code.ts:3:1

(Note - on the same machine, Node.js is able to run puppeteer just fine)

@kt3k
Copy link
Member

kt3k commented Dec 12, 2024

npm:puppeteer depends on lifecycle script for downloading Chrome. You first need to enable lifecycle script by setting the below in deno.json:

{
  "nodeModulesDir": "auto"
}

Then you need to run the command:

deno install --allow-scripts=npm:[email protected]

(The version number may vary. This command should appear in the error message when "nodeModulesDir": "auto" is set)

This command should download Chrome at appropriate path, and should make puppeteer dependency work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants