Skip to content

Playwright CDP fails to connect to Lightpanda on Bun (WebSocket closes with 1006) #2019

@rejantoverlani

Description

@rejantoverlani

Summary

We’re trying to use Lightpanda with Playwright (CDP) to generate PDFs in our API, but the connection fails when running on Bun.

This is currently blocking us from using Lightpanda in production.

We only use Playwright in this project (no Puppeteer).


Setup

  • Lightpanda: v1.2.0

  • Playwright Core: v1.58.2

  • Runtime: Bun 1.3.9

  • Lightpanda started with:

    lightpanda serve --port 9222
    

What we’re doing

const browser = await chromium.connectOverCDP({
  endpointURL: "ws://127.0.0.1:9222/",
});

Error

This is the exact error we’re getting:

Failed to connect to Lightpanda CDP at ws://127.0.0.1:9222/: overCDP: WebSocket error: ws://127.0.0.1:9222/ 101 Switching Protocols

Call log:
 - <ws connecting> ws://127.0.0.1:9222/
 - <ws unexpected response> ws://127.0.0.1:9222/ 101 Switching Protocols
 - <ws error> ws://127.0.0.1:9222/ error WebSocket was closed before the connection was established
 - <ws connect error> ws://127.0.0.1:9222/ WebSocket was closed before the connection was established
 - <ws disconnected> ws://127.0.0.1:9222/ code=1006 reason=

From logs:

connection successfully upgraded
connection closed: error.ConnectionResetByPeer

Behavior

  • Connection starts
  • Server responds with 101 Switching Protocols
  • Then connection immediately closes (code 1006)
  • Playwright never establishes a session

Fails on Bun

If we build with:

bun build --target bun
  • WebSocket fails immediately
  • Same code, same Lightpanda instance

Context

  • This is for a large project (exam platform)
  • We generate PDFs at scale
  • Frontend runs on Node
  • API runs on Bun
  • We want to use Lightpanda for performance reasons

Switching everything to Node just to make this work isn’t ideal for us.


Question

Is Playwright + Lightpanda expected to work on Bun?

Or is this a known limitation with CDP / WebSocket handling?


Related


What we need

Just trying to understand:

  • Is this expected to work?
  • If not, is there a recommended setup for Playwright users?
  • Any workaround we should try?

Happy to test anything or provide more logs if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions