My app hooks in beforeunload with a confirmation message and then MSW stops working
See original GitHub issueDescribe the bug
I have some code in my page that hooks in beforeunload and then the user can cancel and stay in the page or leave the page. If the user decides to stay in the page msw gets broken.
Environment
msw: 0.35.0
nodejs: v17.4.0
npm: 8.3.1
nuxt 3
vite
Please also provide your browser version.
Firefox 98.0b
To Reproduce
Steps to reproduce the behavior:
Add some code like:
window.addEventListener("beforeunload", function(e) {
const confirmationMessage = "Msw will not work from this point";
e.returnValue = confirmationMessage; // Gecko, Trident, Chrome 34+
return confirmationMessage; // Gecko, WebKit, Chrome <34
});
Cancel and remain in the page Trigger some mocked mutation
Expected behavior
Mutation should be triggered
Screenshots
I can go to .vite generated code and delete those lines and then the mutation is triggered.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Easy fix for: Blocked attempt to show a 'beforeunload ...
The fix is pretty straightforward: Make sure the user interacts with your page before showing the beforeunload confirmation box. If the user did ......
Read more >reactjs event listener beforeunload added but not removed
I am removing the eventListener from the component on componentWillUnmount . Then why it is not being removed? How can I remove the...
Read more >Sure you want to leave?—browser beforeunload event
In the video, I explain a bit about the beforeunload event—which lets you prompt or warn your user that they're about to leave...
Read more >Untitled
#Kid Free giveaway of the day game, Koleksi foto hyohyuk, Csync2 ubuntu, ... orange line stops, Profesor bochenek opinie, Three core values of...
Read more >React - CodeProject
A post method is working fine with Postman but not working in react native and getting error code 400. The api working from...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m having the same problem.
The order
beforeunloads
are executed is the order in which they are registered, so msw’s beforeunload is executed first before e.stopImmediatePropagation or e.stopPropagation is executed in the application.Is there any way to do this? Like restarting the worker when beforeunloading?
UPDATE
I tried to start the worker again beforeunload, but the following error occurred.
Same here 😛 - as described evt.preventDefault() is not working, because it is to late. Any updates?