Skip to content

The "Deploy a Browser Rendering Worker with Durable Objects" sample code doesn't work. #20984

@mantaroh

Description

@mantaroh

Existing documentation URL(s)

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.jsonc config:

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions