From 7d10f4b9a440107d4fd42ea2d0b3600f63ccf637 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Thu, 25 Nov 2021 09:27:15 +0000 Subject: [PATCH] [FIX] web: allow navigation by changing the value of browser.location The browser object is meant to allow easily patching some native browser behaviour when writing tests. Outside of test code, it should behave like the corresponding properties on the window object. Previously, the location property of the browser object held a reference to the native window location property. While this works perfectly fine for reading or writing things on the location object, a common use case is to overwrite window.location with a string to navigate to a url. This use case was not covered by browser.location This commit fixes that by replacing the browser.location property with a getter/setter pair, where setting a value on browser.location will do the same thing on window.location closes odoo/odoo#80543 X-original-commit: e838c76b1656dc289ff35e89283b8cc82e636df7 Related: odoo/enterprise#22590 Signed-off-by: Lucas Perais (lpe) Signed-off-by: Samuel Degueldre --- addons/web/static/src/core/browser/browser.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/core/browser/browser.js b/addons/web/static/src/core/browser/browser.js index 62d19e48b0f..b67c32ff560 100644 --- a/addons/web/static/src/core/browser/browser.js +++ b/addons/web/static/src/core/browser/browser.js @@ -26,7 +26,6 @@ export const browser = Object.assign({}, owl.browser, { requestAnimationFrame: window.requestAnimationFrame.bind(window), cancelAnimationFrame: window.cancelAnimationFrame.bind(window), console: window.console, - location: window.location, history: window.history, navigator: navigator, open: window.open.bind(window), @@ -35,6 +34,16 @@ export const browser = Object.assign({}, owl.browser, { sessionStorage, }); +Object.defineProperty(browser, "location", { + set(val) { + window.location = val; + }, + get() { + return window.location; + }, + configurable: true, +}); + // ----------------------------------------------------------------------------- // memory localStorage // -----------------------------------------------------------------------------