cypress: window.location.replace not working - inserts `__` into url
Current behavior:
Navigating within our application using location.replace("") in a chained promise handler throws a cross-origin error. In our actual application, we are waiting on a network request, then navigating using location.replace() in a then handler.
I’ve simplified the code to the most basic thing I can, and am able to reproduce by calling location.replace() in a simple setTimeout.
window.location.replace("") – works
setTimeout(() =>{
window.location.replace("");
});
– gives the following error: SecurityError: Blocked a frame with origin "http://localhost:58236" from accessing a cross-origin frame.
Desired behavior:
I need to be able to call location.replace() in a chained promise handler.
Steps to reproduce: (app code and test code)
https://github.com/beckee/cypress-test-tiny
Versions
Cypress 3.2.0 Mac OSX Chrome Version 73
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 20 (9 by maintainers)
Commits related to this issue
- fix #3975, #3994 — committed to cypress-io/cypress by flotwig 4 years ago
- Rewrite JS/HTML using AST-based approach (#5273) * Add winPropAccessor to security.js, remove other replacers * Add start of Cypress.resolveWindowReference * Add regexes for dot and bracket acc... — committed to cypress-io/cypress by flotwig 4 years ago
This fix is available starting in
4.6.0as an experiment which you can access by setting this config option in yourcypress.jsonor elsewhere:The fix is experimental, so there may be some situations where the
_/rerouting is not fixed.If you’re still experiencing
_/rerouting while setting theexperimentalSourceRewritingto true in 4.6.0 - open a new issue with a reproducible example + screenshots, etc - filling out our issue template.@jennifer-shehane it has been filed here: https://github.com/cypress-io/cypress/issues/7565
For anyone struggling with this in the meantime, a workaround is to reference the window object outside the timeout, and use that reference in the function called by the timeout, e.g: