"Blocked attempt to show a 'beforeunload' confirmation panel" when navigating away from MenuPart editor
See original GitHub issueDescribe the bug
To Reproduce
This is vague and needs more investigation since I see the actual browser log entry only during UI tests (here). Thus I don’t have a solid repro, but the issue does come up reliably if you run that test. So, supposedly:
- Navigate to a MenuPart editor, e.g. the editor of Main Menu when you’ve set up the site with the blog recipe.
- Don’t do anything (?) or perhaps only edit the Title (but not the menu items, don’t change their order, for example).
- Do anything that causes you to navigate away.
- Note a browser console entry similar to this one in Chrome:
3/21/2022 7:49:13 PM UTC | Severe | intervention | https://localhost:9024/Admin/Contents/ContentItems/4nqq58rc9skbf6pdnmhzn3mmx7/Edit?admin=-1181914940 - Blocked attempt to show a 'beforeunload' confirmation panel for a frame that never had a user gesture since its load. https://www.chromestatus.com/feature/5082396709879808
This is because of the window.onbeforeunload code in MenuPart.Edit.cshtml (though it ought to not display a dialog unless the menu items’ order is changed). See the linked https://chromestatus.com/feature/5082396709879808 and https://developer.mozilla.org/en-US/docs/Web/API/BeforeUnloadEvent.
Note that TaxonomyPart.Edit.cshtml has the same issue.
Expected behavior
No console log entry.
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (16 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 >'beforeunload' Chrome Issue - javascript
Actually what I am trying to do is to log details whenever user tries to close the browser. function LogTime() { jQuery.ajax({ type:...
Read more >Sure you want to leave?—browser beforeunload event
It causes following error: Blocked attempt to show a 'beforeunload' confirmation panel for a frame that never had a user gesture since its...
Read more >Window: beforeunload event - Web APIs | MDN
This event enables a web page to trigger a confirmation dialog asking the user if they really want to leave the page. If...
Read more >How to prevent JavaScript alerts that fire when leaving a ...
Well, the simplest thing to do is simply override the pages script directly, and reassign the event to null . window.onbeforeunload = null;....
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 Free
Top 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
You should see the browser window when you use the default config of the sample project. Otherwise, set
falsehere: https://github.com/Lombiq/UI-Testing-Toolbox/blob/a874a575e177016a56cf846a12371b730e0f0298/Lombiq.Tests.UI.Samples/UITestBase.cs#L56Check out https://github.com/OrchardCMS/OrchardCore/pull/11194 and run the
TestAdminPagesAsMonkeyRecursivelyShouldWorkWithAdminUsertest without theconfiguration.AssertBrowserLogassignment. You should get this error within a few seconds. (If you attach the debugger and break at exceptions, you can also stop the test at that point.)