Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation Fault in Lightpanda during Playwright CDP Connection #384

Open
adamdelezuch89 opened this issue Jan 27, 2025 · 1 comment
Open

Comments

@adamdelezuch89
Copy link

Description

I am encountering a segmentation fault within the lightpanda browser when attempting to connect to it using Playwright's connect_over_cdp method. This occurs immediately after websocket connection is established successfully and when playwright tries to get browser version from cdp. This issue prevents me from using Playwright with lightpanda.

Steps to Reproduce

Set the LIGHTPANDA_PATH environment variable to the path of the lightpanda executable.

Run the following Python code:

from dotenv import load_dotenv

load_dotenv()


def test_connect_browser():
    import os
    from playwright.sync_api import sync_playwright
    import os
    import subprocess
    import time

    lightpanda_path = os.getenv("LIGHTPANDA_PATH", "")

    process = subprocess.Popen([
        lightpanda_path,
        "--host", "127.0.0.1",
        "--port", "9222",
        "--verbose",
    ])

    time.sleep(2)  # 2 sekundy powinny wystarczyć

    with sync_playwright() as p:
        ws_endpoint = "ws://127.0.0.1:9222"  # Uproszczony endpoint bez dodatkowej ścieżki
        browser = p.chromium.connect_over_cdp(ws_endpoint)
        
        page = browser.new_page()
        page.goto("https://mail.google.com/mail/u/0/#inbox")
        page.wait_for_load_state()

        input("Press the Enter key to close the browser...")

        browser.close()
        process.terminate()  # Dodajemy zamknięcie procesu


if __name__ == '__main__':
    test_connect_browser()

Error Logs

python tests/test_playwright.py 
debug(cli): Server opts: listening internally on /tmp/lightpanda...
info(websocket): starting blocking worker to listen on 127.0.0.1:9222
info(server): accepting new conn...
debug(websocket): (127.0.0.1:54548) connected
debug(handler): connected to Stream server
debug(websocket): (127.0.0.1:54548) connection successfully upgraded
info(server): client connected
debug(websocket): (127.0.0.1:54548) received text message
debug(cdp): Req > id 1, method browser.getVersion
debug(cdp): Res > id 1, sessionID null, result { }
Segmentation fault at address 0x4
/home/runner/work/browser/browser/vendor/websocket.zig/src/server/server.zig:1289:28: 0x1545fe8 in writeFrame (lightpanda)
/home/runner/work/browser/browser/vendor/websocket.zig/src/server/server.zig:1238:31: 0x154632d in send (lightpanda)
/home/runner/work/browser/browser/src/server.zig:278:29: 0x160b6f2 in wrapper (lightpanda)
/opt/hostedtoolcache/zig/0.13.0/x64/lib/std/debug.zig:0:9: 0x152d042 in run_for_ns (lightpanda)
/home/runner/work/browser/browser/src/server.zig:476:31: 0x152b238 in handle (lightpanda)
/opt/hostedtoolcache/zig/0.13.0/x64/lib/std/Thread.zig:429:13: 0x152e0ae in entryFn (lightpanda)
./nptl/pthread_create.c:442:8: 0x7e5b05294ac2 in start_thread (pthread_create.c)
../sysdeps/unix/sysv/linux/x86_64/clone3.S:81:0: 0x7e5b0532684f in ??? (../sysdeps/unix/sysv/linux/x86_64/clone3.S)
???:?:?: 0x0 in ??? (???)
debug(websocket): (127.0.0.1:54548) connection closed: error.Closed
error(handler): stream close error: error.BrokenPipe
Traceback (most recent call last):
  File "/home/temp/web-ui/tests/test_playwright.py", line 39, in <module>
    test_connect_browser()
  File "/home/temp/web-ui/tests/test_playwright.py", line 26, in test_connect_browser
    browser = p.chromium.connect_over_cdp(ws_endpoint)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/temp/web-ui/.venv/lib/python3.11/site-packages/playwright/sync_api/_generated.py", line 14826, in connect_over_cdp
    self._sync(
  File "/home/temp/web-ui/.venv/lib/python3.11/site-packages/playwright/_impl/_sync_base.py", line 115, in _sync
    return task.result()
           ^^^^^^^^^^^^^
  File "/home/temp/web-ui/.venv/lib/python3.11/site-packages/playwright/_impl/_browser_type.py", line 174, in connect_over_cdp
    response = await self._channel.send_return_as_dict("connectOverCDP", params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/temp/web-ui/.venv/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 67, in send_return_as_dict
    return await self._connection.wrap_api_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/temp/web-ui/.venv/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 528, in wrap_api_call
    raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.TimeoutError: BrowserType.connect_over_cdp: Timeout 30000ms exceeded.
Call log:
  - <ws connecting> ws://127.0.0.1:9222/
  -   - <ws connected> ws://127.0.0.1:9222/

Environment

Operating System: Ubuntu 22.04

Python Version: 3.12.7

Playwright Version: 1.49.1

Lightpanda Version: Nightly

@krichprollsch
Copy link
Member

Hello @adamdelezuch89,
Thanks for the report.
We have issues with playwright's CDP support.
I will try to reproduce yours in the next days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants