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

ReferenceError: _cuprite is not defined #219

Open
rubendinho opened this issue Nov 28, 2022 · 7 comments
Open

ReferenceError: _cuprite is not defined #219

rubendinho opened this issue Nov 28, 2022 · 7 comments

Comments

@rubendinho
Copy link

Since upgrading Cuprite to 0.14.3 and Ferrum to 0.13.0, we're seeing intermittent errors in our RSpec runs on Github Actions. We are not seeing errors like this locally.

Failure/Error: click_on 'Get started'

     Ferrum::JavaScriptError:
       ReferenceError: _cuprite is not defined

Would appreciate any tips on mitigating this.

@rubendinho
Copy link
Author

rubendinho commented Jan 24, 2023

Getting this very frequently on CI (never locally) which makes us reconsider using this project. Happy to try to patch but not sure where to start.

I did notice that this error seems to occur right after switching to an iframe.

@rubendinho
Copy link
Author

Turned out that adding a page.driver.wait_for_network_idle right after switching to the iframe fixed this. I think it's happening on CI because Cuprite is executing too quickly there.

@route
Copy link
Member

route commented Jan 24, 2023

That might be the case, but overall I had a few workarounds just because Chrome doesn't work properly and doesn't load scripts before loading the page https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-addScriptToEvaluateOnNewDocument I can try to check if this changed because that was long time ago.

@jclusso
Copy link

jclusso commented Mar 9, 2023

Seeing this randomly too with iframes.

@zedtux
Copy link

zedtux commented May 9, 2023

Also facing the same issue since I have upgraded from 0.14.2. Adding page.driver.wait_for_network_idle before it fails helps a lot, thank you @rubendinho 👍

@zedtux
Copy link

zedtux commented May 9, 2023

Actually, even with page.driver.wait_for_network_idle or a custom begin ... rescue sleep X; retry end I can't get my tests passing, I'm downgrading to 0.14.2 again.

@baygeldin
Copy link

baygeldin commented Jun 22, 2023

I hit the same issue and after some investigation realized that this is because Cuprite's extensions (source) were not properly injected into the new window opened during a test.

This seems to be a bug in Chrome itself because Ferrum actually does inject the extensions and I double-checked this by debugging inject_extensions method (source). Furthermore, when I updated my Chromium version to the bleeding edge, the issue was gone. But I think it's still present in the majority of Docker images that we run in CI.

I tried manually injecting extensions as a workaround, but it didn't work reliably:

current_browser = page.driver.browser
new_window_handle = current_browser.window_handles.last
target = current_browser.targets[new_window_handle]

target.page.send(:inject_extensions)

What did work though, is refreshing the driver after switching to the new window:

page.driver.refresh

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

No branches or pull requests

5 participants