Selenium::WebDriver::Error::NoScriptResultError localStorage error when running a spec that doesn't visit any pages
When running a JavaScript spec(:js
which runs in Chrome) that doesn't visit
any pages, our global after
hook executes some JavaScript that throws an error, https://gitlab.com/gitlab-org/gitlab-ce/blob/f7254a4060b30e3134c6cf932eaba0fc8e249e9a/spec/support/capybara.rb#L59
This error occurs on Chrome Headless or normal Chrome.
Failure/Error: execute_script("localStorage.clear();")
Selenium::WebDriver::Error::NoScriptResultError:
<unknown>: Failed to read the 'localStorage' property from 'Window': Storage is disabled inside 'data:' URLs.
(Session info: chrome=63.0.3239.70)
(Driver info: chromedriver=2.33.506106 (8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2),platform=Mac OS X 10.12.6 x86_64)
This doesn't actually happen in our feature specs but you can run into this while developing a new spec and it isn't immediately obvious what is wrong. You might use sign_in(user)
which doesn't move you to a page vs gitlab_sign_in(user)
which does.
Potential solutions
Add a current_path
check for about:blank
and only execute_script
if you are actually on a page.
Or perhaps we want to incorporate isLocalStorageAccessSafe
(mentioned by @lbennett) but we would probably have to make it global.
Thanks to @mikegreiling for figuring this one out, https://gitlab.slack.com/archives/C02PF508L/p1511993594000370?thread_ts=1511992385.000396&cid=C02PF508L