[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) <lpe@odoo.com> Signed-off-by: Samuel Degueldre <sad@odoo.com>
This commit is contained in:
@@ -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
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user