Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Workers version of Puppeteer Core

This repo is a fork of main puppeteer project. It creates a version of
puppeteer core specialized for use in Cloudflare workers.
puppeteer core specialized for use in Cloudflare workers [Browser Rendering](https://developers.cloudflare.com/browser-rendering) API.

The goals of the fork are:

Expand All @@ -14,6 +14,13 @@ Note that the main branch in this repo is branched off of version 17.0.0 of
the library, to match the currently deployed version of Chromium on the
edge.

### Requirements

- You need [Wrangler](https://github.com/cloudflare/workers-sdk) 3.0.0 or higher.
- Puppeteer requires a few Node.js APIs to work. Add `compatibility_flags = [ "nodejs_compat" ]` to your [wrangler.toml](https://developers.cloudflare.com/workers/wrangler/configuration/) configuration.

Read our [Developer Documentation](https://developers.cloudflare.com/browser-rendering/platform/puppeteer/) for more information.

Original README follows...

# Puppeteer
Expand Down
2 changes: 1 addition & 1 deletion compat/cjs/compat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {dirname} from 'path';
import {dirname} from 'node:path';

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflare/puppeteer",
"version": "0.0.4",
"version": "0.0.5",
"description": "A high-level API to control headless Chrome over the DevTools Protocol for use in Workers",
"keywords": [
"puppeteer",
Expand Down
4 changes: 2 additions & 2 deletions src/common/ElementHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,9 @@ export class ElementHandle<
);

// Locate all files and confirm that they exist.
let path: typeof import('path');
let path: typeof import('node:path');
try {
path = await import('path');
path = await import('node:path');
} catch (error) {
if (error instanceof TypeError) {
throw new Error(
Expand Down
18 changes: 3 additions & 15 deletions src/common/IsolatedWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,21 +366,9 @@ export class IsolatedWorld {
}

if (path !== null) {
let fs;
try {
fs = (await import('fs')).promises;
} catch (error) {
if (error instanceof TypeError) {
throw new Error(
'Can only pass a filepath to addScriptTag in a Node-like environment.'
);
}
throw error;
}
let contents = await fs.readFile(path, 'utf8');
contents += '//# sourceURL=' + path.replace(/\n/g, '');
const context = await this.executionContext();
return await context.evaluateHandle(addScriptContent, contents, id, type);
throw new Error(
'Can only pass a filepath to addScriptTag in a Node-like environment.'
);
}

if (content !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {dirname} from 'path';
import {dirname} from 'node:path';
import {puppeteerDirname} from './compat.js';

/**
Expand Down
16 changes: 3 additions & 13 deletions src/util/getPackageDirectory.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import {existsSync} from 'fs';
import {dirname, join, parse} from 'path';

export const getPackageDirectory = (from: string): string => {
let found = existsSync(join(from, 'package.json'));
const root = parse(from).root;
while (!found) {
if (from === root) {
throw new Error('Cannot find package directory');
}
from = dirname(from);
found = existsSync(join(from, 'package.json'));
}
return from;
throw new Error(
`Can only use the filesystem in a Node-like environment (${from}).`
);
};