From 5a36ab42c534ff750e1bbd697538b3c4f4925dfc Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Tue, 19 Dec 2023 20:19:30 -0500 Subject: [PATCH] =?UTF-8?q?Revert=20"change=20script=20injection=20approac?= =?UTF-8?q?h=20to=20use=20a=20temporary=20` element is created, - // so we add the script to instead. - if (typeof document === "object" && document instanceof HTMLDocument) { - document.documentElement.appendChild(script); - if (script.parentNode) { - script.parentNode?.removeChild(script); + script.setAttribute("type", "module"); + script.setAttribute("src", browser.runtime.getURL("hook.js")); + document.addEventListener("DOMContentLoaded", () => { + const importMap = document.querySelector('script[type="importmap"]'); + if (importMap != null) { + importMap.parentNode?.insertBefore(script, importMap.nextSibling); + } else { + const head = + document.head || + document.getElementsByTagName("head")[0] || + document.documentElement; + head.insertBefore(script, head.lastChild); } - } + }); }