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

Process stuck due to potential unhandled TargetClosedError #319

Open
jasondoc3 opened this issue Dec 6, 2024 · 0 comments
Open

Process stuck due to potential unhandled TargetClosedError #319

jasondoc3 opened this issue Dec 6, 2024 · 0 comments

Comments

@jasondoc3
Copy link

jasondoc3 commented Dec 6, 2024

Step To Reproduce / Observed behavior

It has been challenging to reproduce the issue since the connection is established via CDP to a remote Chromium browser. However, over the past day, I have intermittently encountered an unhandled TargetClosedError. This error causes the Ruby process running the Playwright Ruby client to consume a significant amount of CPU and hang indefinitely. Here's some of the output when running the process with DEBUG=1. It appears the page is never successfully opened.

SEND>{:id=>3, :guid=>"browser@64858567dee0c11bb46d8f8eefd43927", :method=>"newContext", :params=>{}}
RECV>{"guid"=>"browser@64858567dee0c11bb46d8f8eefd43927", "method"=>"__create__", "params"=>{"type"=>"Tracing", "initializer"=>{}, "guid"=>"tracing@c99f87434fb705fb5d7dc093c8aba1f8"}}
RECV>{"guid"=>"browser@64858567dee0c11bb46d8f8eefd43927", "method"=>"__create__", "params"=>{"type"=>"APIRequestContext", "initializer"=>{"tracing"=>{"guid"=>"tracing@c99f87434fb705fb5d7dc093c8aba1f8"}}, "guid"=>"request-context@0412a83860e84cd22c721ff524e435d0"}}
RECV>{"guid"=>"request-context@0412a83860e84cd22c721ff524e435d0", "method"=>"__adopt__", "params"=>{"guid"=>"tracing@c99f87434fb705fb5d7dc093c8aba1f8"}}
RECV>{"guid"=>"browser@64858567dee0c11bb46d8f8eefd43927", "method"=>"__create__", "params"=>{"type"=>"BrowserContext", "initializer"=>{"isChromium"=>true, "requestContext"=>{"guid"=>"request-context@0412a83860e84cd22c721ff524e435d0"}, "tracing"=>{"guid"=>"tracing@c99f87434fb705fb5d7dc093c8aba1f8"}}, "guid"=>"browser-context@c4688f1a8f708f77756900eabe2d8ba2"}}
RECV>{"guid"=>"browser-context@c4688f1a8f708f77756900eabe2d8ba2", "method"=>"__adopt__", "params"=>{"guid"=>"request-context@0412a83860e84cd22c721ff524e435d0"}}
RECV>{"guid"=>"browser-context@c4688f1a8f708f77756900eabe2d8ba2", "method"=>"__adopt__", "params"=>{"guid"=>"tracing@c99f87434fb705fb5d7dc093c8aba1f8"}}
RECV>{"id"=>3, "result"=>{"context"=>{"guid"=>"browser-context@c4688f1a8f708f77756900eabe2d8ba2"}}}
SEND>{:id=>4, :guid=>"browser-context@c4688f1a8f708f77756900eabe2d8ba2", :method=>"newPage", :params=>{}}
RECV>{"guid"=>"browser-context@c4688f1a8f708f77756900eabe2d8ba2", "method"=>"__create__", "params"=>{"type"=>"Frame", "initializer"=>{"url"=>"", "name"=>"", "loadStates"=>["commit"]}, "guid"=>"frame@ed25769b7aa641c7078f0eefe507e30d"}}
RECV>{"guid"=>"browser-context@c4688f1a8f708f77756900eabe2d8ba2", "method"=>"__create__", "params"=>{"type"=>"Page", "initializer"=>{"mainFrame"=>{"guid"=>"frame@ed25769b7aa641c7078f0eefe507e30d"}, "viewportSize"=>{"width"=>1280, "height"=>720}, "isClosed"=>true}, "guid"=>"page@9cd9326e533113b94eb7c4f65ec5f3a8"}}
RECV>{"guid"=>"page@9cd9326e533113b94eb7c4f65ec5f3a8", "method"=>"__adopt__", "params"=>{"guid"=>"frame@ed25769b7aa641c7078f0eefe507e30d"}}
RECV>{"guid"=>"browser-context@c4688f1a8f708f77756900eabe2d8ba2", "method"=>"page", "params"=>{"page"=>{"guid"=>"page@9cd9326e533113b94eb7c4f65ec5f3a8"}}}
RECV>{"guid"=>"page@9cd9326e533113b94eb7c4f65ec5f3a8", "method"=>"close"}
RECV>{"guid"=>"page@9cd9326e533113b94eb7c4f65ec5f3a8", "method"=>"__dispose__", "params"=>{}}
/opt/homebrew/lib/node_modules/playwright/node_modules/playwright-core/lib/server/chromium/crPage.js:500
    this._firstNonInitialNavigationCommittedReject(new _errors.TargetClosedError());
                                                   ^

TargetClosedError: Target page, context or browser has been closed
    at FrameSession.dispose (/opt/homebrew/lib/node_modules/playwright/node_modules/playwright-core/lib/server/chromium/crPage.js:500:52)
    at CRPage.didClose (/opt/homebrew/lib/node_modules/playwright/node_modules/playwright-core/lib/server/chromium/crPage.js:162:60)
    at CRBrowser._onDetachedFromTarget (/opt/homebrew/lib/node_modules/playwright/node_modules/playwright-core/lib/server/chromium/crBrowser.js:200:14)
    at CRSession.emit (node:events:519:28)
    at /opt/homebrew/lib/node_modules/playwright/node_modules/playwright-core/lib/server/chromium/crConnection.js:160:14

Node.js v22.9.0
# cdp_url = "wss:// ..."
Playwright.create(playwright_cli_executable_path: 'playwright') do |playwright|
  playwright.chromium.connect_over_cdp(cdp_url) do |browser|
    page = browser.new_page
    page.set_default_timeout(60_000)
    # ... never proceeds past here
  end
end

Expected behavior

A Playwright::TargetClosedError exception is thrown

Environment

playwright-ruby-client 1.49.0

ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin23
@jasondoc3 jasondoc3 changed the title Process stuck due to potential unhandled TargetClosedErorr Process stuck due to potential unhandled TargetClosedError Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant