-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Description
Existing documentation URL(s)
- https://developers.cloudflare.com/browser-rendering/workers-binding-api/browser-rendering-with-do/#5-configure-your-wrangler-configuration-file
- https://developers.cloudflare.com/browser-rendering/workers-binding-api/browser-rendering-with-do/#6-code
What changes are you suggesting?
I attempted to write code with browser rendering by following the documentation. However, I was unable to run it successfully.
I've identified two issues within the documentation:
wrangler.jsoncconfig:
The documentation currently recommends using nodejs_compat. However, it should be updated to use nodejs_compat_v2 instead. The reasoning for this change can be found here: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag
suggestion:
"compatibility_flags": [
"nodejs_compat_v2"
],
- Puppeteer's screenshot parameter:
The screenshot() parameter should be removed from the documentation's example. Puppeteer's implementation of this function relies on Node.js's fs module. In my testing, using this parameter resulted in the error: Error: [unenv] fs.writeFile is not implemented yet!. After removing the screenshot() parameter, the worker ran without any issues."
suggestion:
for (let i = 0; i < width.length; i++) {
await page.setViewport({ width: width[i], height: height[i] });
await page.goto("https://workers.cloudflare.com/");
const fileName = "screenshot_" + width[i] + "x" + height[i];
const sc = await page.screenshot();
await this.env.BUCKET.put(folder + "/" + fileName + ".jpg", sc);
}
Error detail
{
level:
"error",
message:
"Error: [unenv] fs.writeFile is not implemented yet!",
$metadata:
{
now:
********,
id:
"********",
requestId:
"********",
trigger:
"GET /",
service:
"crawler",
error:
"Error: [unenv] fs.writeFile is not implemented yet!",
message:
"Error: [unenv] fs.writeFile is not implemented yet!",
account:
"********",
type:
"cf-worker",
fingerprint:
"********",
origin:
"fetch",
messageTemplate:
"Error: [unenv] <DOMAIN> is not implemented yet!",
errorTemplate:
"Error: [unenv] <DOMAIN> is not implemented yet!",
},
$workers:
{
truncated:
false,
event:
{
request:
{
url:
"https://***.*****.workers.dev/",
method:
"GET",
path:
"/"
}
},
outcome:
"ok",
scriptName:
"crawler",
eventType:
"fetch",
executionModel:
"stateless",
scriptVersion:
{
id:
"********"
},
requestId:
"********"
}
}
Additional information
No response