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

[BUG] when using arg --single-process, page.context.browser.new_page() will raise Browser closed error #1453

Closed
Unintendedz opened this issue Jul 26, 2022 · 7 comments
Labels

Comments

@Unintendedz
Copy link

Unintendedz commented Jul 26, 2022

Context:

  • Playwright Version: playwright = "^1.23.1"
  • Operating System: WSL2 Ubuntu 22.04
  • Python version: python = "^3.10"
  • Browser: Chromium

Code Snippet

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(args=["--single-process"])
    page = browser.new_page()
    page.goto("http://playwright.dev")
    
    page2 = page.context.browser.new_page() # playwright._impl._api_types.Error: Browser closed. 
    
    print(page.title())
    browser.close()

Describe the bug

When using arg --single-process, page.context.browser.new_page() will raise playwright._impl._api_types.Error: Browser closed.

@rwoll
Copy link
Member

rwoll commented Jul 26, 2022

Try setting DEBUG env var to pw:browser to see more specific errors from the browser. While custom args can be supplied, once used there may be unanticipated issues.

@rwoll rwoll added the triaging label Jul 26, 2022
@Unintendedz
Copy link
Author

Hi, Thanks for your response. I've tried setting DEBUG to pw:browser

  pw:browser <launching> /home/x/.cache/ms-playwright/chromium-1015/chrome-linux/chrome --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync --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 --export-tagged-pdf --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --single-process --user-data-dir=/tmp/playwright_chromiumdev_profile-9z7NdE --remote-debugging-pipe --no-startup-window +0ms
  pw:browser <launched> pid=15812 +2ms
  pw:browser [pid=15812][err] [0727/035948.169897:ERROR:bus.cc(398)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory +40ms
  pw:browser [pid=15812][err] [0727/035948.169974:ERROR:bus.cc(398)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory +0ms
  pw:browser [pid=15812][err] [0727/035948.260411:WARNING:audio_manager_linux.cc(60)] Falling back to ALSA for audio output. PulseAudio is not available or could not be initialized. +90ms
  pw:browser [pid=15812][err] [0727/035948.261666:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable. +1ms
  pw:browser [pid=15812][err] [0727/035950.795875:FATAL:render_process_host_impl.cc(4541)] Check failed: render_process_host->InSameStoragePartition( browser_context->GetStoragePartition(site_instance, false )).  +3s
  pw:browser [pid=15812][err] #0 0x55f4bc7b4fb9 base::debug::CollectStackTrace() +0ms
  pw:browser [pid=15812][err] #1 0x55f4bc727853 base::debug::StackTrace::StackTrace() +1ms
  pw:browser [pid=15812][err] #2 0x55f4bc7249a0 logging::LogMessage::~LogMessage() +0ms
  pw:browser [pid=15812][err] #3 0x55f4bc72559e logging::LogMessage::~LogMessage() +0ms
  pw:browser [pid=15812][err] #4 0x55f4ba5bab01 content::RenderProcessHostImpl::GetProcessHostForSiteInstance() +0ms
  pw:browser [pid=15812][err] #5 0x55f4ba6850b4 content::SiteInstanceImpl::GetProcess() +0ms
  pw:browser [pid=15812][err] #6 0x55f4ba59a2fb content::RenderFrameHostManager::CreateRenderFrameHost() +0ms
  pw:browser [pid=15812][err] #7 0x55f4ba59a20e content::RenderFrameHostManager::InitRoot() +0ms
  pw:browser [pid=15812][err] #8 0x55f4ba4b729f content::FrameTree::Init() +0ms
  pw:browser [pid=15812][err] #9 0x55f4ba6da1ed content::WebContentsImpl::Init() +0ms
  pw:browser [pid=15812][err] #10 0x55f4ba6cda46 content::WebContentsImpl::CreateWithOpener() +0ms
  pw:browser [pid=15812][err] #11 0x55f4c205b53e headless::HeadlessWebContentsImpl::Create() +0ms
  pw:browser [pid=15812][err] #12 0x55f4c2060da8 headless::HeadlessBrowserContextImpl::CreateWebContents() +0ms
  pw:browser [pid=15812][err] #13 0x55f4c206a213 headless::protocol::TargetHandler::CreateTarget() +0ms
  pw:browser [pid=15812][err] #14 0x55f4c206a379 headless::protocol::TargetHandler::CreateTarget() +0ms
  pw:browser [pid=15812][err] #15 0x55f4c2070730 headless::protocol::Target::DomainDispatcherImpl::createTarget() +0ms
  pw:browser [pid=15812][err] #16 0x55f4bb7220c3 v8_crdtp::UberDispatcher::DispatchResult::Run() +0ms
  pw:browser [pid=15812][err] #17 0x55f4c2067a38 headless::protocol::HeadlessDevToolsSession::HandleCommand() +0ms
  pw:browser [pid=15812][err] #18 0x55f4c20656a8 headless::HeadlessDevToolsManagerDelegate::HandleCommand() +0ms
  pw:browser [pid=15812][err] #19 0x55f4ba23e58e content::DevToolsSession::DispatchProtocolMessageInternal() +0ms
  pw:browser [pid=15812][err] #20 0x55f4ba23df7b content::DevToolsSession::DispatchProtocolMessage() +0ms
  pw:browser [pid=15812][err] #21 0x55f4ba23a162 base::internal::FunctorTraits<>::Invoke<>() +0ms
  pw:browser [pid=15812][err] #22 0x55f4bc771010 base::TaskAnnotator::RunTaskImpl() +0ms
  pw:browser [pid=15812][err] #23 0x55f4bc784bfc base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl() +0ms
  pw:browser [pid=15812][err] #24 0x55f4bc7847ad base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() +1ms
  pw:browser [pid=15812][err] #25 0x55f4bc785172 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() +0ms
  pw:browser [pid=15812][err] #26 0x55f4bc72e193 base::MessagePumpGlib::Run() +0ms
  pw:browser [pid=15812][err] #27 0x55f4bc7853e3 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run() +0ms
  pw:browser [pid=15812][err] #28 0x55f4bc74daed base::RunLoop::Run() +0ms
  pw:browser [pid=15812][err] #29 0x55f4ba1b3cad content::BrowserMainLoop::RunMainMessageLoop() +0ms
  pw:browser [pid=15812][err] #30 0x55f4ba1b54f2 content::BrowserMainRunnerImpl::Run() +0ms
  pw:browser [pid=15812][err] #31 0x55f4c205e8ee headless::HeadlessContentMainDelegate::RunProcess() +0ms
  pw:browser [pid=15812][err] #32 0x55f4bc290b42 content::RunBrowserProcessMain() +0ms
  pw:browser [pid=15812][err] #33 0x55f4bc2920da content::ContentMainRunnerImpl::RunBrowser() +0ms
  pw:browser [pid=15812][err] #34 0x55f4bc291c70 content::ContentMainRunnerImpl::Run() +0ms
  pw:browser [pid=15812][err] #35 0x55f4bc28ee1e content::RunContentProcess() +0ms
  pw:browser [pid=15812][err] #36 0x55f4bc28f7de content::ContentMain() +0ms
  pw:browser [pid=15812][err] #37 0x55f4bc2e992a headless::(anonymous namespace)::RunContentMain() +0ms
  pw:browser [pid=15812][err] #38 0x55f4bc2e9635 headless::HeadlessShellMain() +0ms
  pw:browser [pid=15812][err] #39 0x55f4b8ba51e3 ChromeMain +0ms
  pw:browser [pid=15812][err] #40 0x7f5be6abbd90 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) +0ms
  pw:browser [pid=15812][err] #41 0x7f5be6abbe40 __libc_start_main +0ms
  pw:browser [pid=15812][err] #42 0x55f4b8ba502a _start +0ms
  pw:browser [pid=15812][err] Task trace: +0ms
  pw:browser [pid=15812][err] #0 0x55f4ba239fc5 content::PipeReaderBase::HandleMessage() +0ms
  pw:browser [pid=15812][err] #1 0x55f4ba2398ef content::PipeReaderBase::StartMainLoop() +0ms
  pw:browser [pid=15812][err]  +0ms
  pw:browser [pid=15812] <process did exit: exitCode=null, signal=SIGTRAP> +58ms
  pw:browser [pid=15812] starting temporary directories cleanup +0ms
Traceback (most recent call last):
  File "/home/x/test.py", line 11, in <module>
    page2 = page.context.browser.new_page() # playwright._impl._api_types.Error: Browser closed. 
  File "/home/x/.cache/pypoetry/virtualenvs/playwright-tasks-rNpIEn1m-py3.10/lib/python3.10/site-packages/playwright/sync_api/_generated.py", line 11188, in new_page
    self._sync(
  File "/home/x/.cache/pypoetry/virtualenvs/playwright-tasks-rNpIEn1m-py3.10/lib/python3.10/site-packages/playwright/_impl/_sync_base.py", line 89, in _sync
    return task.result()
  File "/home/x/.cache/pypoetry/virtualenvs/playwright-tasks-rNpIEn1m-py3.10/lib/python3.10/site-packages/playwright/_impl/_browser.py", line 174, in new_page
    page = await context.new_page()
  File "/home/x/.cache/pypoetry/virtualenvs/playwright-tasks-rNpIEn1m-py3.10/lib/python3.10/site-packages/playwright/_impl/_browser_context.py", line 230, in new_page
    return from_channel(await self._channel.send("newPage"))
  File "/home/x/.cache/pypoetry/virtualenvs/playwright-tasks-rNpIEn1m-py3.10/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 43, in send
    return await self._connection.wrap_api_call(
  File "/home/x/.cache/pypoetry/virtualenvs/playwright-tasks-rNpIEn1m-py3.10/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 369, in wrap_api_call
    return await cb()
  File "/home/x/.cache/pypoetry/virtualenvs/playwright-tasks-rNpIEn1m-py3.10/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 78, in inner_send
    result = next(iter(done)).result()
playwright._impl._api_types.Error: Browser closed.
==================== Browser output: ====================
<launching> /home/x/.cache/ms-playwright/chromium-1015/chrome-linux/chrome --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync --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 --export-tagged-pdf --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --single-process --user-data-dir=/tmp/playwright_chromiumdev_profile-9z7NdE --remote-debugging-pipe --no-startup-window
<launched> pid=15812
[pid=15812][err] [0727/035948.169897:ERROR:bus.cc(398)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[pid=15812][err] [0727/035948.169974:ERROR:bus.cc(398)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[pid=15812][err] [0727/035948.260411:WARNING:audio_manager_linux.cc(60)] Falling back to ALSA for audio output. PulseAudio is not available or could not be initialized.
[pid=15812][err] [0727/035948.261666:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable.
[pid=15812][err] [0727/035950.795875:FATAL:render_process_host_impl.cc(4541)] Check failed: render_process_host->InSameStoragePartition( browser_context->GetStoragePartition(site_instance, false )). 
[pid=15812][err] #0 0x55f4bc7b4fb9 base::debug::CollectStackTrace()
[pid=15812][err] #1 0x55f4bc727853 base::debug::StackTrace::StackTrace()
[pid=15812][err] #2 0x55f4bc7249a0 logging::LogMessage::~LogMessage()
[pid=15812][err] #3 0x55f4bc72559e logging::LogMessage::~LogMessage()
[pid=15812][err] #4 0x55f4ba5bab01 content::RenderProcessHostImpl::GetProcessHostForSiteInstance()
[pid=15812][err] #5 0x55f4ba6850b4 content::SiteInstanceImpl::GetProcess()
[pid=15812][err] #6 0x55f4ba59a2fb content::RenderFrameHostManager::CreateRenderFrameHost()
[pid=15812][err] #7 0x55f4ba59a20e content::RenderFrameHostManager::InitRoot()
[pid=15812][err] #8 0x55f4ba4b729f content::FrameTree::Init()
[pid=15812][err] #9 0x55f4ba6da1ed content::WebContentsImpl::Init()
[pid=15812][err] #10 0x55f4ba6cda46 content::WebContentsImpl::CreateWithOpener()
[pid=15812][err] #11 0x55f4c205b53e headless::HeadlessWebContentsImpl::Create()
[pid=15812][err] #12 0x55f4c2060da8 headless::HeadlessBrowserContextImpl::CreateWebContents()
[pid=15812][err] #13 0x55f4c206a213 headless::protocol::TargetHandler::CreateTarget()
[pid=15812][err] #14 0x55f4c206a379 headless::protocol::TargetHandler::CreateTarget()
[pid=15812][err] #15 0x55f4c2070730 headless::protocol::Target::DomainDispatcherImpl::createTarget()
[pid=15812][err] #16 0x55f4bb7220c3 v8_crdtp::UberDispatcher::DispatchResult::Run()
[pid=15812][err] #17 0x55f4c2067a38 headless::protocol::HeadlessDevToolsSession::HandleCommand()
[pid=15812][err] #18 0x55f4c20656a8 headless::HeadlessDevToolsManagerDelegate::HandleCommand()
[pid=15812][err] #19 0x55f4ba23e58e content::DevToolsSession::DispatchProtocolMessageInternal()
[pid=15812][err] #20 0x55f4ba23df7b content::DevToolsSession::DispatchProtocolMessage()
[pid=15812][err] #21 0x55f4ba23a162 base::internal::FunctorTraits<>::Invoke<>()
[pid=15812][err] #22 0x55f4bc771010 base::TaskAnnotator::RunTaskImpl()
[pid=15812][err] #23 0x55f4bc784bfc base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl()
[pid=15812][err] #24 0x55f4bc7847ad base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork()
[pid=15812][err] #25 0x55f4bc785172 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork()
[pid=15812][err] #26 0x55f4bc72e193 base::MessagePumpGlib::Run()
[pid=15812][err] #27 0x55f4bc7853e3 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run()
[pid=15812][err] #28 0x55f4bc74daed base::RunLoop::Run()
[pid=15812][err] #29 0x55f4ba1b3cad content::BrowserMainLoop::RunMainMessageLoop()
[pid=15812][err] #30 0x55f4ba1b54f2 content::BrowserMainRunnerImpl::Run()
[pid=15812][err] #31 0x55f4c205e8ee headless::HeadlessContentMainDelegate::RunProcess()
[pid=15812][err] #32 0x55f4bc290b42 content::RunBrowserProcessMain()
[pid=15812][err] #33 0x55f4bc2920da content::ContentMainRunnerImpl::RunBrowser()
[pid=15812][err] #34 0x55f4bc291c70 content::ContentMainRunnerImpl::Run()
[pid=15812][err] #35 0x55f4bc28ee1e content::RunContentProcess()
[pid=15812][err] #36 0x55f4bc28f7de content::ContentMain()
[pid=15812][err] #37 0x55f4bc2e992a headless::(anonymous namespace)::RunContentMain()
[pid=15812][err] #38 0x55f4bc2e9635 headless::HeadlessShellMain()
[pid=15812][err] #39 0x55f4b8ba51e3 ChromeMain
[pid=15812][err] #40 0x7f5be6abbd90 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
[pid=15812][err] #41 0x7f5be6abbe40 __libc_start_main
[pid=15812][err] #42 0x55f4b8ba502a _start
[pid=15812][err] Task trace:
[pid=15812][err] #0 0x55f4ba239fc5 content::PipeReaderBase::HandleMessage()
[pid=15812][err] #1 0x55f4ba2398ef content::PipeReaderBase::StartMainLoop()
[pid=15812][err] 

@rwoll
Copy link
Member

rwoll commented Jul 26, 2022

Unfortunately, since you're using custom args, I'm unable to debug the crash trace as custom args (especially --single-process) is use at-your-own-risk.

Perhaps there is a way for you to use Playwright without the custom arg.

@rwoll rwoll closed this as completed Jul 26, 2022
@Unintendedz
Copy link
Author

Perhaps there is a way for you to use Playwright without the custom arg.

No, in AWS Lambda, you just can't run Chormium without --single-process even using Docker Image Function.

@rwoll
Copy link
Member

rwoll commented Jul 28, 2022

There are some third-party chrome distributions that may work in these particularly constrained environments. If you're still stuck I recommend asking in https://aka.ms/playwright-slack for others running Playwright in AWS Lambda.

@Unintendedz
Copy link
Author

Thank you for your advice! I didn't realize there might be some third-party chrome distribution for these environments.

For now I'm using BrowserContext instead Browser to create Page, and page.context.new_page() is working fine!

@Michael0700
Copy link

Could you please share working code example? Thank you!

Thank you for your advice! I didn't realize there might be some third-party chrome distribution for these environments.

For now I'm using BrowserContext instead Browser to create Page, and page.context.new_page() is working fine!

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

No branches or pull requests

3 participants