Cannot read properties of undefined (reading 'fetch') with Node

I'm getting this with just running a basic command of @cloudflare/puppeteer that I got from the docs Here's the docs https://developers.cloudflare.com/browser-rendering/platform/puppeteer/#use-puppeteer-in-a-worker
Cloudflare Docs
Puppeteer · Browser Rendering docs
Puppeteer is one of the most popular libraries that abstract the lower-level DevTools protocol from developers and provides a high-level API that you …
No description
6 Replies
Walshy
Walshy7mo ago
Seems like MY_BROWSER isn't set Do you have the binding?
nil3217
nil32177mo ago
I'm facing the same error. I cannot make the getting started guide work — here's the keybinding I use:
#:schema node_modules/wrangler/config-schema.json
name = "round-unit-1901"
main = "src/index.js"
compatibility_date = "2024-05-24"
compatibility_flags = ["nodejs_compat"]

browser = { binding = "MY_BROWSER" }
kv_namespaces = [
{ binding = "BROWSER_KV_DEMO", id = "...", preview_id = "..." }
]
#:schema node_modules/wrangler/config-schema.json
name = "round-unit-1901"
main = "src/index.js"
compatibility_date = "2024-05-24"
compatibility_flags = ["nodejs_compat"]

browser = { binding = "MY_BROWSER" }
kv_namespaces = [
{ binding = "BROWSER_KV_DEMO", id = "...", preview_id = "..." }
]
and here' the index.js file
import puppeteer from '@cloudflare/puppeteer';

export default {
async fetch(request, env) {
const { searchParams } = new URL(request.url);
let url = searchParams.get('url');
let img;
if (url) {
url = new URL(url).toString(); // normalize
console.log(env);
img = await env.BROWSER_KV_DEMO.get(url, { type: 'arrayBuffer' });
if (img === null) {
const browser = await puppeteer.launch(env.MYBROWSER);
const page = await browser.newPage();
await page.goto(url);
img = await page.screenshot();
await env.BROWSER_KV_DEMO.put(url, img, {
expirationTtl: 60 * 60 * 24,
});
await browser.close();
}
return new Response(img, {
headers: {
'content-type': 'image/jpeg',
},
});
} else {
return new Response('Please add an ?url=https://example.com/ parameter');
}
},
};
import puppeteer from '@cloudflare/puppeteer';

export default {
async fetch(request, env) {
const { searchParams } = new URL(request.url);
let url = searchParams.get('url');
let img;
if (url) {
url = new URL(url).toString(); // normalize
console.log(env);
img = await env.BROWSER_KV_DEMO.get(url, { type: 'arrayBuffer' });
if (img === null) {
const browser = await puppeteer.launch(env.MYBROWSER);
const page = await browser.newPage();
await page.goto(url);
img = await page.screenshot();
await env.BROWSER_KV_DEMO.put(url, img, {
expirationTtl: 60 * 60 * 24,
});
await browser.close();
}
return new Response(img, {
headers: {
'content-type': 'image/jpeg',
},
});
} else {
return new Response('Please add an ?url=https://example.com/ parameter');
}
},
};
0xCC
0xCC6mo ago
Hey I am facing the same error, has anyone fixed this problem?
Walshy
Walshy6mo ago
Share code + wrangler.toml Your config will be incorrect
0xCC
0xCC6mo ago
I realize this is only for worker paid user. So I think it is normal that hit an error with a free tier account. Thanks
LeanKhan
LeanKhan4mo ago
hello, I'm a paid user and still get this error :/
Want results from more Discord servers?
Add your server