Skip to content

Javascript errors triggered by cuprite on pages with iframes #200

@hoffi

Description

@hoffi

On pages with iframes cuprite triggers a javascript error when switching into a frame.

I have written a test which shows the errors:

diff --git a/spec/features/driver_spec.rb b/spec/features/driver_spec.rb
index d9f9403..d4c3d7d 100644
--- a/spec/features/driver_spec.rb
+++ b/spec/features/driver_spec.rb
@@ -1555,6 +1555,16 @@ module Capybara
         expect(@session.driver.current_url).to end_with("/cuprite/frames")
       end

+      it "generates no javascript errors with frames" do
+        @driver.browser.evaluate_on_new_document(
+          "window.errors ||= []; window.onerror = function(msg) { window.errors += msg; };" 
+        )
+        @session.visit "/cuprite/frames" 
+
+        @session.within_frame(0) { expect(@session.evaluate_script("window.errors")).to be_empty }
+        expect(@session.evaluate_script("window.errors")).to be_empty
+      end
+
       it "waits for network idle" do
         @session.visit "/cuprite/show_cookies" 
         expect(@session).not_to have_content("test_cookie")

This fails with this message:

Failure/Error: @session.within_frame(0) { expect(@session.evaluate_script("window.errors")).to be_empty }                 
  expected `"Uncaught SyntaxError: Identifier 'InvalidSelector' has already been declared".empty?` to be truthy, got false

However this seems only to happen with Chrome >= 102. When i run this test with Chrome 101 or lower it does not fail.

The identifier InvalidSelector is defined here: https://github.com/rubycdp/cuprite/blob/2bbf3634d92af4e8b8ec3026c2b66ccf1d0590ad/lib/capybara/cuprite/javascripts/index.js.
Looks like these extensions are executed in the same context multiple times with frames?

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