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

  1. Configure Playwright MCP plugin with --isolated flag as documented
  2. Clear cookies with context.clearCookies()
  3. Navigate to http://localhost:3000/login
  4. Page shows loading spinner indefinitely

What I Tried (all failed)

  1. Cleared cookies via page.context().clearCookies() — still fails
  2. Cleared .next cache and restarted dev server (pm2 stop && rm -rf .next && pm2 start) — still fails
  3. Multiple fresh navigations with about:blank intermediate — still fails
  4. Used waitUntil: 'networkidle' and domcontentloaded — page loads but app never renders
  5. 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 --isolated flag 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 function webpack error also appears in server-side logs, possibly related to how Playwright's browser handles HMR/dev mode assets

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗