Skip to content

[BUG] WebSocket error is not notified #755

@YusukeIwaki

Description

@YusukeIwaki

Context:

  • Playwright Version: 1.12
  • Operating System: macOS
  • Python Version: 3.9

Code Snippet

from playwright.sync_api import sync_playwright

with sync_playwright() as playwright:
    browser = playwright.chromium.launch(headless=False)
    try:
        page = browser.new_page()

        errors = []

        def on_web_socket(ws):
            ws.on("socketerror", lambda err: errors.append(err))

        page.on("websocket", on_web_socket)
        page.evaluate("new WebSocket('ws://localhost:8080/invalid-ws-url')")        

        print(errors)
    finally:
        browser.close()

This code is originated from a spec in the TypeScript version of Playwright.
https://github.com/microsoft/playwright/blob/060f7ffa92865db95fcfd8f3fa77ac38d5e79cfa/tests/web-socket.spec.ts#L116-L128

When I execute the script with DEBUG=pw:protocol, WebSocket error is really notified, however the callback of ws.on("socketerror", ... is not called.

  pw:protocol ◀ RECV {"method":"Network.webSocketFrameError","params":{"requestId":"21150.1","timestamp":19371.491694,"errorMessage":"Error during WebSocket handshake: Unexpected response code: 404"},"sessionId":"8B511AAB7B27D8597CE51D735E329871"} +1ms

When I implemented WebSocket in my project (YusukeIwaki/playwright-ruby-client#116) , I just noticed WebSocket should handle socketError event instead of error event here.

"error", lambda params: self.emit(WebSocket.Events.Error, params["error"])

It seems renamed several months ago.
microsoft/playwright#4495

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions