cloudflare/puppeteer

[Bug]: Cannot read properties of undefined (reading 'fetch')

Closed this issue · 4 comments

Bug description

Steps to reproduce the problem:

  1. Run the sample code from the developer documentation

Puppeteer version

0.0.5

Node.js version

18.18.1

npm version

9.8.1

What operating system are you seeing the problem on?

macOS

Relevant log output

 ⛅️ wrangler 3.13.1 (update available 3.13.2)                                                                                        
-------------------------------------------------------                                                                         
⎔ Starting local server...                                                                                             
[mf:inf] Ready on http://0.0.0.0:8787                                                                                                
[mf:inf] - http://127.0.0.1:8787                                                                                                           
[mf:inf] - http://192.168.0.6:8787                                                                                                   
[mf:inf] - http://192.168.64.1:8787                                                                                                        
[mf:err] TypeError: Cannot read properties of undefined (reading 'fetch')                                                            
    at PuppeteerWorkers.launch (/Users/count0/projects/silent-wind-e522/node_modules/@cloudflare/puppeteer/src/puppeteer-core.ts:66:32)         
    at Object.fetch (/Users/count0/projects/silent-wind-e522/src/index.ts:36:35)                                                     
    at __facade_modules_fetch__ (/private/var/folders/_c/br63y4ss5z13yhhrz4bsbnjh0000gn/T/tmp-43437-hYzTQ7KimFbI/middleware-loader.entry.ts:46:16)
    at __facade_invokeChain__ (/Users/count0/projects/silent-wind-e522/node_modules/wrangler/templates/middleware/common.ts:53:9)    
    at Object.next (/Users/count0/projects/silent-wind-e522/node_modules/wrangler/templates/middleware/common.ts:50:11)                         
    at jsonError (/Users/count0/projects/silent-wind-e522/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:30) 
    at __facade_invokeChain__ (/Users/count0/projects/silent-wind-e522/node_modules/wrangler/templates/middleware/common.ts:53:9)          
    at __facade_invoke__ (/Users/count0/projects/silent-wind-e522/node_modules/wrangler/templates/middleware/common.ts:63:9)                    
    at Object.fetch (/private/var/folders/_c/br63y4ss5z13yhhrz4bsbnjh0000gn/T/tmp-43437-hYzTQ7KimFbI/middleware-loader.entry.ts:114:11)              
[mf:inf] GET / 500 Internal Server Error (112ms)                                                                                           
[mf:err] TypeError: Cannot read properties of undefined (reading 'fetch')                                                                       
    at PuppeteerWorkers.launch (/Users/count0/projects/silent-wind-e522/node_modules/@cloudflare/puppeteer/src/puppeteer-core.ts:66:32)    
    at Object.fetch (/Users/count0/projects/silent-wind-e522/src/index.ts:36:35)                                                                
    at __facade_modules_fetch__ (/private/var/folders/_c/br63y4ss5z13yhhrz4bsbnjh0000gn/T/tmp-43437-hYzTQ7KimFbI/middleware-loader.entry.ts:46:16)
    at __facade_invokeChain__ (/Users/count0/projects/silent-wind-e522/node_modules/wrangler/templates/middleware/common.ts:53:9)    
    at Object.next (/Users/count0/projects/silent-wind-e522/node_modules/wrangler/templates/middleware/common.ts:50:11)                    
    at jsonError (/Users/count0/projects/silent-wind-e522/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:30)
    at __facade_invokeChain__ (/Users/count0/projects/silent-wind-e522/node_modules/wrangler/templates/middleware/common.ts:53:9)          
    at __facade_invoke__ (/Users/count0/projects/silent-wind-e522/node_modules/wrangler/templates/middleware/common.ts:63:9)         
    at Object.fetch (/private/var/folders/_c/br63y4ss5z13yhhrz4bsbnjh0000gn/T/tmp-43437-hYzTQ7KimFbI/middleware-loader.entry.ts:114:11)
[mf:inf] GET /favicon.ico 500 Internal Server Error (56ms) 
スクリーンショット 2023-10-18 20 45 20

The API does not work in local mode, use npx wrangler dev --remote to run it.

@meddulla
I tried it, but the result was an error.

❯ npx wrangler dev --remote
 ⛅️ wrangler 3.13.1 (update available 3.13.2)
-------------------------------------------------------
⬣ Listening at http://0.0.0.0:8787
- http://127.0.0.1:8787
- http://192.168.0.6:8787
- http://192.168.64.1:8787
Total Upload: 549.26 KiB / gzip: 94.28 KiB
20:35:15 GET / 500
✘ [ERROR] Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'fetch')

      at launch
  (file:///Users/count0/projects/silent-wind-e522/node_modules/@cloudflare/puppeteer/src/puppeteer-core.ts:65:46)
      at fetch (file:///Users/count0/projects/silent-wind-e522/src/index.ts:34:61)


✘ [ERROR] Uncaught (in response) TypeError: Cannot read properties of undefined (reading 'fetch')


✘ [ERROR] Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'fetch')

      at launch
  (file:///Users/count0/projects/silent-wind-e522/node_modules/@cloudflare/puppeteer/src/puppeteer-core.ts:65:46)
      at fetch (file:///Users/count0/projects/silent-wind-e522/src/index.ts:34:61)


✘ [ERROR] Uncaught (in response) TypeError: Cannot read properties of undefined (reading 'fetch')


20:35:15 GET /favicon.ico 500
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ [b] open a browser, [d] open Devtools, [l] turn on local mode, [c] clear console, [x] to exit                                           │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Can you check your binding name in wrangler.toml, it should be MYBROWSER so it matches the example's env.MYBROWSER:


browser = { binding = "MYBROWSER" }
compatibility_flags = ["nodejs_compat"]
compatibility_date = "2023-10-10"

See https://developers.cloudflare.com/browser-rendering/get-started/screenshots/#4-configure-wranglertoml.

The terminal should show the binding's name as well:

⛅️ wrangler 3.14.0
-------------------
Your worker has access to the following bindings:
- Browser:
  - Name: MYBROWSER
⬣ Listening at http://0.0.0.0:8787

Also, assuming you already have access, if not you'll need to join the waitlist here.

I didn't know it was a private beta and was trying out the code, I signed up for waitlist.

Thanks, @meddula.