Repository navigation
[Bug]: Protocol error when setting env for non-headless browsers #833
Copy link
Copy link
Closed
Labels
Description
Playwright version
1.13.1
Operating system
Linux
What browsers are you seeing the problem on?
WebKit
Other information
python 3.8
ubuntu 20.04
What happened? / Describe the bug
When running the following code
from playwright.sync_api import sync_playwright
def run(playwright):
chromium = playwright.chromium
browser = chromium.launch(headless=False, env={"a": "b"})
page = browser.new_page()
page.goto("https://example.com")
print(page.title())
browser.close()
with sync_playwright() as playwright:
run(playwright)Playwright report Protocol Error:
Traceback (most recent call last):
File "tmp.py", line 14, in <module>
run(playwright)
File "tmp.py", line 6, in run
browser = chromium.launch(headless=False, env={"a": "b"})
File "/path/to/lib/python3.8/site-packages/playwright/sync_api/_generated.py", line 9703, in launch
self._sync(
File "/path/to/lib/python3.8/site-packages/playwright/_impl/_sync_base.py", line 111, in _sync
return task.result()
File "/path/to/lib/python3.8/site-packages/playwright/_impl/_browser_type.py", line 90, in launch
raise e
File "/path/to/lib/python3.8/site-packages/playwright/_impl/_browser_type.py", line 86, in launch
return from_channel(await self._channel.send("launch", params))
File "/path/to/lib/python3.8/site-packages/playwright/_impl/_connection.py", line 36, in send
return await self.inner_send(method, params, False)
File "/path/to/lib/python3.8/site-packages/playwright/_impl/_connection.py", line 54, in inner_send
result = next(iter(done)).result()
playwright._impl._api_types.Error: Protocol error (Browser.getVersion): Browser closed.
==================== Browser output: ====================
<launching> /home/.cache/ms-playwright/chromium-901522/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --user-data-dir=/tmp/playwright_chromiumdev_profile-jYIBcX --remote-debugging-pipe --no-sandbox --no-startup-window
<launched> pid=239241
[pid=239241][err] [239241:239241:0805/023206.685664:ERROR:browser_main_loop.cc(1409)] Unable to open X display.
=========================== logs ===========================
<launching> /home/.cache/ms-playwright/chromium-901522/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --user-data-dir=/tmp/playwright_chromiumdev_profile-jYIBcX --remote-debugging-pipe --no-sandbox --no-startup-window
<launched> pid=239241
[pid=239241][err] [239241:239241:0805/023206.685664:ERROR:browser_main_loop.cc(1409)] Unable to open X display.
============================================================
Found this bug in all three browsers. It seems that headless=False is incompatible with env argument.
Code snippet to reproduce your bug
No response
Relevant log output
No response
Reactions are currently unavailable
Activity
mxschmitt commentedon Aug 4, 2021
See here how to fix it: https://playwright.dev/docs/ci#running-headed
Relates microsoft/playwright#6037
ChijinZ commentedon Aug 4, 2021
It is not because xvbf hasn't been installed. For my case, I can run
browser = webkit.launch(headless=False)successfully but fail inbrowser = webkit.launch(headless=False, env={"a": "b"}).I just figured out the root cause.
envargument will overwrite the parent's env, while xvbf useDISPLAYenv var to tell process where to display. So be careful to deal with env inheritance. the following code works.