[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) <dmo@odoo.com>
Co-authored-by: Jinjiu Liu <jili@odoo.com>
Co-authored-by: David Monjoie <dmo@odoo.com>
This commit is contained in:
David Monjoie
2023-05-02 14:47:28 +02:00
co-authored by Jinjiu Liu
parent 439a3b1683
commit d0e14f6064
@@ -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,