Playwright Headless Crash

Issue: “Target page, context or browser has been closed” error when launching Playwright browser on Render

Description:
I have an endpoint in my application that sends a prompt to an browser-use AI agent. The agent then uses Playwright to launch a browser and execute tasks specified in the prompt.

Build Command:
pip install playwright && python -m playwright install && pip install -r requirements.txt

Browser Configuration:
I’m setting up the browser with headless mode enabled. Here’s the relevant configuration snippet:

config = BrowserConfig(
headless=True, # Running in headless mode
disable_security=True,
extra_chromium_args=[
‘–no-sandbox’, # Include no-sandbox flag
],
proxy=None
)
browser = Browser(config=config)

Error Details:
During deployment, I’m encountering the following error when trying to launch the browser:

Failed to initialize Playwright browser: BrowserType.launch: Target page, context or browser has been closed

Browser logs:

  • pid=320
  • [pid=320][err] [320:335:0324/094450.346787:ERROR:bus.cc(408)] Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
  • [pid=320][err] [320:320:0324/094450.349221:ERROR:ozone_platform_x11.cc(245)] Missing X server or $DISPLAY
  • [pid=320][err] [320:320:0324/094450.349242:ERROR:env.cc(257)] The platform failed to initialize. Exiting.

Any insights or suggestions would be greatly appreciated!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.