Playwright MCP plugin: persistent 'Invalid or unexpected token' error prevents page loading
Resolved 💬 2 comments Opened Mar 18, 2026 by rangotek Closed Apr 15, 2026
Bug Description
The Playwright MCP plugin (@playwright/mcp@latest with --isolated flag) consistently fails to load pages in a local Next.js dev environment with an Invalid or unexpected token error in the browser console. Pages get stuck on a loading spinner and never render.
Environment
- Claude Code CLI (latest)
- Playwright MCP config:
npx @playwright/mcp@latest --isolated - Target: Next.js 15.4.6 dev server on
http://localhost:3000 - OS: Ubuntu Linux (5.15.0-171-generic)
Steps to Reproduce
- Configure Playwright MCP plugin with
--isolatedflag as documented - Clear cookies with
context.clearCookies() - Navigate to
http://localhost:3000/login - Page shows loading spinner indefinitely
What I Tried (all failed)
- Cleared cookies via
page.context().clearCookies()— still fails - Cleared
.nextcache and restarted dev server (pm2 stop && rm -rf .next && pm2 start) — still fails - Multiple fresh navigations with
about:blankintermediate — still fails - Used
waitUntil: 'networkidle'anddomcontentloaded— page loads but app never renders - Waited 15+ seconds for compilation — server compiles fine but browser shows spinner
Console Output
The browser console only shows:
[283ms] Invalid or unexpected token
No stack trace, no file reference — just the bare error message repeated on each navigation attempt.
The Next.js server logs show successful compilation:
✓ Compiled /login in 5.6s (692 modules)
GET /login 200 in 6463ms
Expected Behavior
Page should load and render the login form, allowing interaction via Playwright snapshot/click tools.
Actual Behavior
Page gets stuck on loading spinner. The accessibility snapshot shows only:
- generic [active]:
- region "Notifications alt+T"
No form elements, no interactive content rendered.
Notes
- The
--isolatedflag is used per workaround guidance to keep browser profile in memory only - The Next.js server itself works fine when accessed via a regular browser
- The
__webpack_modules__[moduleId] is not a functionwebpack error also appears in server-side logs, possibly related to how Playwright's browser handles HMR/dev mode assets
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗