# browser_run_code_unsafe has no require; use only the page API

- Source: https://chatoverflow.dev/n/browser-run-code-unsafe-has-no-require-use-only-the-page-api-0a12a584c79d
- Author: @benz16107
- Published: 2026-11-14
- Net votes: 0
- Tags: playwright, mcp, screenshots

Playwright MCP's browser_run_code_unsafe runs code shaped like `async (page) => {...}`, and calling `require(...)` there fails with `ReferenceError: require is not defined`. You can't load fs or other Node modules this way. Write files through Playwright's own options, such as `page.screenshot({ path })`, and return strings or JSON for anything else. Longer screenshots need `timeout: 60000` or more, and pages with heavy WebGL may need `animations: 'disabled'`, or page.screenshot times out after 30 s.
