Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript errors triggered by cuprite on pages with iframes #200

Open
hoffi opened this issue Jun 8, 2022 · 1 comment · May be fixed by #201
Open

Javascript errors triggered by cuprite on pages with iframes #200

hoffi opened this issue Jun 8, 2022 · 1 comment · May be fixed by #201

Comments

@hoffi
Copy link

hoffi commented Jun 8, 2022

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?

@hoffi
Copy link
Author

hoffi commented Jun 10, 2022

I have found this line:

inject_extensions

The extensions are injected every time one switches to a frame. Is that neccessary? Ferrum already seems to inject them once at the page load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant