fix: Scripts injection for content-scripts on Firefox MV2 target#2232
Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2232 +/- ##
==========================================
+ Coverage 76.66% 79.50% +2.83%
==========================================
Files 117 130 +13
Lines 3163 3805 +642
Branches 711 860 +149
==========================================
+ Hits 2425 3025 +600
- Misses 656 694 +38
- Partials 82 86 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@wxt-dev/analytics
@wxt-dev/auto-icons
@wxt-dev/browser
@wxt-dev/i18n
@wxt-dev/is-background
@wxt-dev/module-react
@wxt-dev/module-solid
@wxt-dev/module-svelte
@wxt-dev/module-vue
@wxt-dev/runner
@wxt-dev/storage
@wxt-dev/unocss
@wxt-dev/webextension-polyfill
wxt
commit: |
|
@PatrykKuniczak My explanation at #2183 (comment) was insufficient. With the current code, Current code in the PR: if (isManifestV3) {
// Event handlers (load, error) are registered before the script execution.
// However, since `await` is used here, it will wait forever for the `load` event to fire.
await makeLoadedPromise(script);
}
await options?.modifyScript?.(script);
(document.head ?? document.documentElement).append(script);
if (!options?.keepInDom) {
script.remove();
}Previous code (current main branch): // Event handlers are registered before the script execution.
// Since `await` is not used, execution doesn't pause here.
const loadedPromise = makeLoadedPromise(script);
await options?.modifyScript?.(script);
// At this point, the event handlers are guaranteed to be registered.
(document.head ?? document.documentElement).append(script);
if (!options?.keepInDom) {
script.remove();
}
// Wait for the `load` event to fire here.
// However, the `load` event doesn't fire in MV2.
await loadedPromise;Based on the above, I think it would be better to implement the fix as follows: // Register the event handlers only for MV3.
const loadedPromise = isManifestV3 ? makeLoadedPromise(script) : undefined;
await options?.modifyScript?.(script);
(document.head ?? document.documentElement).append(script);
if (!options?.keepInDom) {
script.remove();
}
if (isManifestV3) {
await loadedPromise;
}
// This alternative might be better:
// if (loadedPromise) {
// await loadedPromise;
// }I'm not entirely sure if this code is perfectly correct, but I have confirmed that it works properly on Firefox MV2 and Chrome MV3. |
|
@nines75 I was wondering, if this is necessary to do it that way, because it work's anyway. But i've checked it, and const loadedPromise = isManifestV3 ? makeLoadedPromise(script) : Promise.resolve();works as well, we need to wait for @aklinker1 review, if we'll approve your suggestion, i'll do it, that's no problem :) I'm not sure, my simplification is good approach 😆 |
Co-authored-by: Aaron <aaronklinker1@gmail.com>
remove async=false
aklinker1
left a comment
There was a problem hiding this comment.
Confirmed its working with the latest changes.
|
@aklinker1 Yeah, that one also works. |
Overview
I've fixed issue with awaited injectScript for Firefox MV2, which isn't included in build files.
Manual Testing
Let's try code from mentioned issue reproduction
This PR closes #2183
Code with example for that'll be merged in #2233