File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ def event_name(event)
6161
6262 class Client
6363 extend Forwardable
64+
6465 delegate %i[ timeout timeout= ] => :options
6566
6667 attr_reader :ws_url , :options , :subscriber
@@ -165,7 +166,7 @@ def raise_browser_error(error)
165166 "Inspected target navigated or closed"
166167 raise NodeNotFoundError , error
167168 # Context is lost, page is reloading
168- when "Cannot find context with specified id"
169+ when "Cannot find context with specified id" , /Failed to find context with id/
169170 raise NoExecutionContextError , error
170171 when "No target with given id found"
171172 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
@@ -46,11 +47,18 @@ def create(**options)
4647 context
4748 end
4849
49- def dispose ( context_id )
50+ def dispose ( context_id ) # rubocop:disable Naming/PredicateMethod
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