Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ferrum/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def raise_browser_error(error)
"Inspected target navigated or closed"
raise NodeNotFoundError, error
# Context is lost, page is reloading
when "Cannot find context with specified id"
when "Cannot find context with specified id", /Failed to find context with id/
raise NoExecutionContextError, error
when "No target with given id found"
raise NoSuchPageError
Expand Down
12 changes: 10 additions & 2 deletions lib/ferrum/contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Ferrum
class Contexts
ALLOWED_TARGET_TYPES = %w[page iframe].freeze
ABOUT_BLANK = "about:blank"

include Enumerable

Expand Down Expand Up @@ -49,8 +50,15 @@ def create(**options)
def dispose(context_id)
context = @contexts[context_id]
context.close_targets_connection
@client.command("Target.disposeBrowserContext", browserContextId: context.id)
@contexts.delete(context_id)

begin
@client.command("Target.disposeBrowserContext", browserContextId: context.id)
rescue NoExecutionContextError
warn "Browser context #{context.id} was already disposed" unless context.page&.url == ABOUT_BLANK
ensure
@contexts.delete(context_id)
end

true
end

Expand Down
Loading