diff --git a/CHANGELOG.md b/CHANGELOG.md index 47a6221b..b348e23f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ the browser; a failed `IO.close` is raised to the caller. ### Fixed +- An out-of-process iframe, e.g. Chrome's PDF viewer for an embedded PDF, appearing while a web worker was connected + raised `'Page.enable' wasn't found` in the event thread. Only pages and iframes are now searched for its parent [#640] - A browser context whose `Target.disposeBrowserContext` timed out stayed registered, so every later `#reset` asked again and raised `Disposal of browser context ... is already pending` for the rest of the process. It's now forgotten either way, and `#reset` disposes the remaining contexts before raising the first error [#641] diff --git a/lib/ferrum/contexts.rb b/lib/ferrum/contexts.rb index f3b0a9d4..45cc7f73 100644 --- a/lib/ferrum/contexts.rb +++ b/lib/ferrum/contexts.rb @@ -178,8 +178,7 @@ def subscribe_target_created context_id = info["browserContextId"] add_context(context_id) - if info["type"] == "iframe" && - (target = @contexts[context_id]&.find_target { |t| t.connected? && t.page.frame_by(id: info["targetId"]) }) + if info["type"] == "iframe" && (target = find_frame_owner(context_id, info["targetId"])) @contexts[context_id]&.add_target(session_id: target.session_id, params: info) else @contexts[context_id]&.add_target(params: info) @@ -205,6 +204,12 @@ def subscribe_target_created end end + def find_frame_owner(context_id, frame_id) + @contexts[context_id]&.find_target do |target| + (target.page? || target.iframe?) && target.connected? && target.page.frame_by(id: frame_id) + end + end + def rearm_auto_attach(session_id, type) return unless RECURSIVE_AUTO_ATTACH_TYPES.include?(type) diff --git a/sig/ferrum/contexts.rbs b/sig/ferrum/contexts.rbs index 73c3ac76..c575b1a1 100644 --- a/sig/ferrum/contexts.rbs +++ b/sig/ferrum/contexts.rbs @@ -43,6 +43,8 @@ module Ferrum def subscribe_target_created: () -> void + def find_frame_owner: (String? context_id, String frame_id) -> Target? + def rearm_auto_attach: (String session_id, String type) -> void def handle_attach: (Target? target, String session_id, Hash[String, untyped] params) -> void