"Blocked attempt to show a 'beforeunload' confirmation panel" when navigating away from MenuPart editor

See original GitHub issue

Describe 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:

  1. Navigate to a MenuPart editor, e.g. the editor of Main Menu when you’ve set up the site with the blog recipe.
  2. Don’t do anything (?) or perhaps only edit the Title (but not the menu items, don’t change their order, for example).
  3. Do anything that causes you to navigate away.
  4. 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:closed
  • Created 2 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
Piedonecommented, Dec 26, 2022

You should see the browser window when you use the default config of the sample project. Otherwise, set false here: https://github.com/Lombiq/UI-Testing-Toolbox/blob/a874a575e177016a56cf846a12371b730e0f0298/Lombiq.Tests.UI.Samples/UITestBase.cs#L56

1reaction
Piedonecommented, Oct 26, 2022

Check out https://github.com/OrchardCMS/OrchardCore/pull/11194 and run the TestAdminPagesAsMonkeyRecursivelyShouldWorkWithAdminUser test without the configuration.AssertBrowserLog assignment. 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.)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found