Skip to content

Commit

Permalink
fix: don't connect to iframe in pages
Browse files Browse the repository at this point in the history
  • Loading branch information
route committed Feb 26, 2025
1 parent 3de015a commit b908edf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/ferrum/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def page
end

def pages
@targets.values.map(&:page)
@targets.values.reject(&:iframe?).map(&:page)
end

# When we call `page` method on target it triggers ruby to connect to given
Expand Down
8 changes: 5 additions & 3 deletions lib/ferrum/contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

module Ferrum
class Contexts
ALLOWED_TARGET_TYPES = %w[page iframe].freeze

include Enumerable

attr_reader :contexts
Expand Down Expand Up @@ -71,7 +73,7 @@ def size
def subscribe
@client.on("Target.attachedToTarget") do |params|
info, session_id = params.values_at("targetInfo", "sessionId")
next unless %w[page iframe].include?(info["type"])
next unless ALLOWED_TARGET_TYPES.include?(info["type"])

context_id = info["browserContextId"]
@contexts[context_id]&.add_target(session_id: session_id, params: info)
Expand All @@ -82,7 +84,7 @@ def subscribe

@client.on("Target.targetCreated") do |params|
info = params["targetInfo"]
next unless %w[page iframe].include?(info["type"])
next unless ALLOWED_TARGET_TYPES.include?(info["type"])

context_id = info["browserContextId"]

Expand All @@ -96,7 +98,7 @@ def subscribe

@client.on("Target.targetInfoChanged") do |params|
info = params["targetInfo"]
next unless %w[page iframe].include?(info["type"])
next unless ALLOWED_TARGET_TYPES.include?(info["type"])

context_id, target_id = info.values_at("browserContextId", "targetId")
@contexts[context_id]&.update_target(target_id, info)
Expand Down

0 comments on commit b908edf

Please sign in to comment.