File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -165,7 +165,7 @@ def raise_browser_error(error)
165165 "Inspected target navigated or closed"
166166 raise NodeNotFoundError , error
167167 # Context is lost, page is reloading
168- when "Cannot find context with specified id"
168+ when "Cannot find context with specified id" , /Failed to find context with id/
169169 raise NoExecutionContextError , error
170170 when "No target with given id found"
171171 raise NoSuchPageError
Original file line number Diff line number Diff line change 55module Ferrum
66 class Contexts
77 ALLOWED_TARGET_TYPES = %w[ page iframe ] . freeze
8+ ABOUT_BLANK = "about:blank"
89
910 include Enumerable
1011
@@ -49,8 +50,15 @@ def create(**options)
4950 def dispose ( context_id )
5051 context = @contexts [ context_id ]
5152 context . close_targets_connection
52- @client . command ( "Target.disposeBrowserContext" , browserContextId : context . id )
53- @contexts . delete ( context_id )
53+
54+ begin
55+ @client . command ( "Target.disposeBrowserContext" , browserContextId : context . id )
56+ rescue NoExecutionContextError
57+ warn "Browser context #{ context . id } was already disposed" unless context . page &.url == ABOUT_BLANK
58+ ensure
59+ @contexts . delete ( context_id )
60+ end
61+
5462 true
5563 end
5664
You can’t perform that action at this time.
0 commit comments