teamcapybara/capybara · error · ArgumentError

Not allowed to close the primary window

Error message

Not allowed to close the primary window

What it means

Error "Not allowed to close the primary window" thrown in teamcapybara/capybara.

Source

Thrown at lib/capybara/selenium/driver.rb:236

      browser.manage.window.resize_to(width, height)
    end
  end

  def maximize_window(handle)
    within_given_window(handle) do
      browser.manage.window.maximize
    end
    sleep 0.1 # work around for https://code.google.com/p/selenium/issues/detail?id=7405
  end

  def fullscreen_window(handle)
    within_given_window(handle) do
      browser.manage.window.full_screen
    end
  end

  def close_window(handle)
    raise ArgumentError, 'Not allowed to close the primary window' if handle == window_handles.first

    within_given_window(handle) do
      browser.close
    end
  end

  def window_handles
    browser.window_handles
  end

  def open_new_window(kind = :tab)
    if browser.switch_to.respond_to?(:new_window)
      handle = current_window_handle
      browser.switch_to.new_window(kind)
      switch_to_window(handle)
    else
      browser.manage.new_window(kind)
    end

View on GitHub (pinned to 15b5fdb76e)

When it happens

Trigger: Thrown at lib/capybara/selenium/driver.rb:236 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of teamcapybara/capybara@15b5fdb76e (2026-08-21). Data as JSON: /api/errors/d6a27805009bb266. Report an issue: GitHub.