"Blocked attempt to show a 'beforeunload' confirmation panel" when navigating away from MenuPart editor
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:
- 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.
Time to move away from JQuery UI.
Do you think that's causing this, not our custom code?
To me, it seems to be part of the component itself.
@Piedone can this reproduced in Edge, so I can check and submit a PR for it
Don't do anything (?) or perhaps only edit the Title (but not the menu items, don't change their order, for example).
@Piedone do you mean edit the tilte for menu or menu item?
Do anything that causes you to navigate away.
Can I navigate to any of the admin menus?
FYI I tried to edit "About" menu item, then I click one of the menu items links, nothing show up in the console. Still I'm not sure if this issue reproduced in all the browsers or Chrome only?
- The Title of the menu.
- I think so, yes. So, clicking any of the other navigation items on the left should suffice too.
- Note that this is about the Menu editor, not the Menu Items'.
As I mentioned in the issue, I couldn't reproduce it manually, only the UI test did it, though both happened in Chrome. UI tests run a blank Chrome profile though (i.e. without my personal settings and extensions like ad blockers) that might affect this. However, you said you could reproduce it in Edge (I assume the Chromium one, so similar environment).
Could you please run the UI test on Edge, or you could share the test with me then I can reproduce the issue. Seems it's hard to reproduce it manually
I won't be able to in the next days, but if you checkout the OSOCE solution, the test linked in the issue will be there. If you change the [Theory, Chrome] attributes on it to [Theory, Edge] then it should be run in Edge (but we didn't use Edge, this happened under Chrome).
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.)
@Piedone I run the test in both Edge & Chrome but I can't reproduce the issue
BTW is there an option to see and trace the current browser page, coz I didn't see any browser instance even I choose debug the test
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
I'm successfully execute the test, this time with browser instance opened, while the monkey testing finished nothing show up or should I open the console logs?
Note that the bug doesn't always reproduce, it comes up randomly. So you may need a couple of tries to see the test fail with an exception that the browser log contains this error. (Be sure to remove the configuration.AssertBrowserLog assignment as I mentioned under https://github.com/OrchardCMS/OrchardCore/issues/11420#issuecomment-1292780872, otherwise it'll ignore the error.)
(Be sure to remove the configuration.AssertBrowserLog assignment as I mentioned under https://github.com/OrchardCMS/OrchardCore/issues/11420#issuecomment-1292780872, otherwise it'll ignore the error.)
I already remove it. I may need to try this test 10 times at least and see if the exception show up
(Be sure to remove the configuration.AssertBrowserLog assignment as I mentioned under https://github.com/OrchardCMS/OrchardCore/issues/11420#issuecomment-1292780872, otherwise it'll ignore the error.)
I already remove it. I may need to try this test 10 times at least and see if the exception show up
I can't reproduce this now either, neither locally nor in CI. Perhaps a Chrome update or the update to Bootstrap 5 fixed this somehow. Anyway, good bug, fixed itself!