diff --git a/addons/web/static/src/webclient/actions/action_service.js b/addons/web/static/src/webclient/actions/action_service.js index f9989bdd411..c031c65a319 100644 --- a/addons/web/static/src/webclient/actions/action_service.js +++ b/addons/web/static/src/webclient/actions/action_service.js @@ -833,7 +833,17 @@ function makeActionManager(env) { */ function _executeActURLAction(action, options) { if (action.target === "self") { + let willUnload = false; + const onUnload = () => { + willUnload = true; + }; + browser.addEventListener("beforeunload", onUnload); + env.services.ui.block(); env.services.router.redirect(action.url); + browser.removeEventListener("beforeunload", onUnload); + if (!willUnload) { + env.services.ui.unblock(); + } } else { const w = browser.open(action.url, "_blank"); if (!w || w.closed || typeof w.closed === "undefined") { diff --git a/addons/web/static/tests/webclient/actions/url_action_tests.js b/addons/web/static/tests/webclient/actions/url_action_tests.js index e62ca8813f4..c2d793cbc68 100644 --- a/addons/web/static/tests/webclient/actions/url_action_tests.js +++ b/addons/web/static/tests/webclient/actions/url_action_tests.js @@ -36,6 +36,31 @@ QUnit.module("ActionManager", (hooks) => { assert.verifySteps(["/my/test/url"]); }); + QUnit.test("an 'ir.actions.act_url' with target 'self' blocks the ui", async (assert) => { + serviceRegistry.add( + "ui", + { + start() { + return { + block: () => assert.step("block"), + // we can't simulate a page unload in the tests, so in this scenario the + // ui will be unblocked directly (and we thus need to define the unblock + // function) + unblock: () => {}, + }; + }, + } + ); + setupWebClientRegistries(); + const env = await makeTestEnv({ serverData }); + await doAction(env, { + type: "ir.actions.act_url", + target: "self", + url: "/my/test/url", + }); + assert.verifySteps(["block"]); + }); + QUnit.test("execute an 'ir.actions.act_url' action with onClose option", async (assert) => { setupWebClientRegistries(); patchWithCleanup(browser, {