[FIX] web: avoid popover crash in iframe

This commit solves a crash which can happen when a popover points to an
element inside an iframe that has been removed from the DOM. In those
cases, the element's ownerDocument does not have a defaultView.

closes odoo/odoo#151235

X-original-commit: 1ccebdbd2fcc6875173b02a31d89f3c2e9ffbfec
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
This commit is contained in:
Julien Carion (juca)
2024-01-26 09:13:07 +00:00
parent 6c736a7795
commit 01aa0621b9
@@ -145,8 +145,12 @@ Popover.props = {
validate: (target) => {
// target may be inside an iframe, so get the Element constructor
// to test against from its owner document's default view
const Element = target?.ownerDocument?.defaultView.Element;
return Boolean(Element) && (target instanceof Element || target instanceof window.Element);
const Element = target?.ownerDocument?.defaultView?.Element;
return (
(Boolean(Element) &&
(target instanceof Element || target instanceof window.Element)) ||
(typeof target === "object" && target?.constructor?.name?.endsWith("Element"))
);
},
},
slots: {