diff --git a/lib/ferrum/context.rb b/lib/ferrum/context.rb index 37d59072..f085aa26 100644 --- a/lib/ferrum/context.rb +++ b/lib/ferrum/context.rb @@ -72,6 +72,10 @@ def dispose @contexts.dispose(@id) end + def has_target?(target_id) + @targets.keys.include?(target_id) + end + def inspect %(#<#{self.class} @id=#{@id.inspect} @targets=#{@targets.inspect} @default_target=#{@default_target.inspect}>) end diff --git a/lib/ferrum/contexts.rb b/lib/ferrum/contexts.rb index 66c70511..9ab3a28c 100644 --- a/lib/ferrum/contexts.rb +++ b/lib/ferrum/contexts.rb @@ -7,7 +7,7 @@ class Contexts attr_reader :contexts def initialize(browser) - @contexts = Concurrent::Hash.new + @contexts = Concurrent::Map.new @browser = browser subscribe discover @@ -18,7 +18,9 @@ def default_context end def find_by(target_id:) - @contexts.find { |_, c| c.targets.keys.include?(target_id) }&.last + context = nil + @contexts.each_value { |c| context = c if c.has_target?(target_id) } + context end def create