From d0e14f6064dc05acee2506e216dce24dabb7de3f Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Thu, 27 Apr 2023 14:39:24 +0000 Subject: [PATCH] [FIX] web_editor: fix ClipboardJS traceback in Firefox 109 Starting with Firefox 109, a widget element prototype that is put inside an iframe will not be instanceof its original constructor. See: https://github.com/webcompat/web-bugs/issues/118350 This is because a node that is adopted by an iframe will have its prototype changed to match the constructor from within the iframe instead of its original one. This has been the case for a long time. See: https://bugzilla.mozilla.org/show_bug.cgi?id=1470017 It largely went unnoticed because of another quirk of Firefox related to the use of instanceof which was fixed in version 109. See: https://bugzilla.mozilla.org/show_bug.cgi?id=1360715 Since this bug was fixed it became apparent, in the form of a traceback, that the wrong instance of ClipboardJS was being used in the case of Firefox, due to the forced prototype change. This commit could be reverted once Firefox is fixed. Steps to reproduce the issue in Firefox > 109: - Create a new mass mailing. - Choose the third template with "Thank you for joining us!". - Click on the "LOGIN" button link inside the email. - Get a traceback about a paremeter not being the right type. Task-3186513 OPW-3172914 closes odoo/odoo#120171 X-original-commit: c0da01c716716f9d35abe9d90dad27cce1452ebb Signed-off-by: David Monjoie (dmo) Co-authored-by: Jinjiu Liu Co-authored-by: David Monjoie --- .../static/src/js/wysiwyg/widgets/link_popover_widget.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js index 424e3311025..fe7263d01ba 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js @@ -37,6 +37,14 @@ const LinkPopoverWidget = Widget.extend({ this.$copyLink = this.$('.o_we_copy_link'); this.$fullUrl = this.$('.o_we_full_url'); + // Use the right ClipboardJS with respect to the prototype of this.el + // since, starting with Firefox 109, a widget element prototype that is + // adopted by an iframe will not be instanceof its original constructor. + // See: https://github.com/webcompat/web-bugs/issues/118350 + const ClipboardJS = + this.el instanceof HTMLElement + ? window.ClipboardJS + : this.el.ownerDocument.defaultView.ClipboardJS; // Copy onclick handler // ClipboardJS uses "instanceof" to verify the elements passed to its // constructor. Unfortunately, when the element is within an iframe,