Skip to content

Commit b908edf

Browse files
committed
fix: don't connect to iframe in pages
1 parent 3de015a commit b908edf

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/ferrum/context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def page
2525
end
2626

2727
def pages
28-
@targets.values.map(&:page)
28+
@targets.values.reject(&:iframe?).map(&:page)
2929
end
3030

3131
# When we call `page` method on target it triggers ruby to connect to given

lib/ferrum/contexts.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
module Ferrum
66
class Contexts
7+
ALLOWED_TARGET_TYPES = %w[page iframe].freeze
8+
79
include Enumerable
810

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

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

8385
@client.on("Target.targetCreated") do |params|
8486
info = params["targetInfo"]
85-
next unless %w[page iframe].include?(info["type"])
87+
next unless ALLOWED_TARGET_TYPES.include?(info["type"])
8688

8789
context_id = info["browserContextId"]
8890

@@ -96,7 +98,7 @@ def subscribe
9698

9799
@client.on("Target.targetInfoChanged") do |params|
98100
info = params["targetInfo"]
99-
next unless %w[page iframe].include?(info["type"])
101+
next unless ALLOWED_TARGET_TYPES.include?(info["type"])
100102

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

0 commit comments

Comments
 (0)