browserbase / stagehand

An AI web browsing framework focused on simplicity and extensibility.
https://www.browserbase.com
MIT License
1.16k stars 43 forks source link

Can't run inside Cloudflare workers due to __dirname usage in stagehand and playwright-core #164

Open labithiotis opened 2 weeks ago

labithiotis commented 2 weeks ago

I would like to run this lib inside the cloudflare workers (if possible) and currently its failing due to usage of _dirname global var. Could where we use __dirname replace it with helper function that uses __dirname if defined otherwise import.meta.dirname or something.

✘ [ERROR] service core:user:extractor: Uncaught ReferenceError: __dirname is not defined

    at null.<anonymous> (worker.js:9810:156)
    at null.<anonymous> (worker.js:7360:58)
    at null.<anonymous> (worker.js:16846:17) in
  node_modules/.pnpm/playwright-core@1.48.2/node_modules/playwright-core/lib/utilsBundleImpl/index.js
    at null.<anonymous> (worker.js:32:50) in __require2
    at null.<anonymous> (worker.js:16901:37) in
  node_modules/.pnpm/playwright-core@1.48.2/node_modules/playwright-core/lib/utilsBundle.js
    at null.<anonymous> (worker.js:32:50) in __require2
    at null.<anonymous> (worker.js:28823:25) in
  node_modules/.pnpm/playwright-core@1.48.2/node_modules/playwright-core/lib/server/registry/index.js
    at null.<anonymous> (worker.js:32:50) in __require2
    at null.<anonymous> (worker.js:76867:21) in
  node_modules/.pnpm/playwright-core@1.48.2/node_modules/playwright-core/lib/server/index.js
    at null.<anonymous> (worker.js:32:50) in __require2

I suspect there may be other issues like access to FS that may prevent this from ever working.

I am also planning on using browserbase browser always so it would be nice if env was "BROWSERBASE" none of this code is included to avoid the issue. Maybe a better solution could be to have different bundled exports for LOCAL and BROWSERBASE instead of env flag so if we import StagehandExternal it doesn't include any browser code, and StagehandLocal does?