Skip to content

switch_to_window does not send Chrome's Target.activateTarget CDP command #321

Description

@vdbijl

We have a patch in our code that speeds up coming back to a window. See the code below.

When a spec switches away from a window and later switches back, Chrome's renderer for that window remains in a backgrounded state. CDP input commands (e.g. Input.dispatchMouseEvent) then stall for ~5 seconds while Chrome reactivates the renderer. This affects any spec that uses multiple windows.
Calling page.activate after switching sends Target.activateTarget, which wakes the renderer immediately. This reduces wait time, on some specs more than 10s.

We use the following patch.

 module CupriteActivateOnSwitch
  # Sends Target.activateTarget after switching, waking Chrome's renderer for the target window.
  # @return [true]
  def switch_to_window(target_id)
    super
    @page.activate
  end
end
Capybara::Cuprite::Browser.class_eval {prepend CupriteActivateOnSwitch}

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