Skip to content

Event thread dies when an iframe target appears while a web worker is connected ('Page.enable' wasn't found) #640

Description

@samuelraub

Ferrum 0.18.0 (also on main), Chrome 138 via browserless, default flatten: true.

When an iframe target is created, Contexts#subscribe_target_created looks for its parent page:

target = @contexts[context_id]&.find_target { |t| t.connected? && t.page.frame_by(id: info["targetId"]) }

find_target yields every connected target, including dedicated workers. t.page builds a Page for the worker target, which sends Page.enable and raises Ferrum::BrowserError: 'Page.enable' wasn't found. The exception is raised on the subscriber's event thread, which ends. After that, no further CDP events are dispatched for the rest of the process, so the next navigation or command that waits for an event hangs until it times out.

We hit it with a page that runs web workers (an OHIF DICOM viewer) and then opens an iframe. A workaround that restricts the lookup to page/iframe targets fixes it for us:

module FindTargetSkipsWorkers
  def find_target
    super { |target| (target.page? || target.type == "iframe") && yield(target) }
  end
end
Ferrum::Context.prepend(FindTargetSkipsWorkers)

Separately: the related case where connect_worker raises TimeoutError for a worker that never answers is already rescued on main. A release with that fix would let us drop our workaround for it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions