ReferenceError: _cuprite is not defined
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.
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.
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.
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.
Seeing this randomly too with iframes.
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 :+1:
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.
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