Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't crash background service worker when using import.meta.url #402

Merged
merged 1 commit into from
Feb 3, 2024

Conversation

aklinker1
Copy link
Collaborator

@aklinker1 aklinker1 commented Feb 3, 2024

This fixes #392.

Vite replaces import.meta.url with document.currentScript && document.currentScript.src || new URL("background.js",document.baseURI).href by default, which crashes in background service worker since document isn't defined. Instead, we're now overriding the definition and replacing import.meta.url with self.location.href, which is defined in all possible JS contexts of chrome extensions.

Copy link

netlify bot commented Feb 3, 2024

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit d8877c1
🔍 Latest deploy log https://app.netlify.com/sites/creative-fairy-df92c4/deploys/65bea79df66cf000081dfd63
😎 Deploy Preview https://deploy-preview-402--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Feb 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9318346) 80.89% compared to head (d8877c1) 80.24%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #402      +/-   ##
==========================================
- Coverage   80.89%   80.24%   -0.65%     
==========================================
  Files         107      108       +1     
  Lines        7761     7782      +21     
  Branches      706      703       -3     
==========================================
- Hits         6278     6245      -33     
- Misses       1467     1521      +54     
  Partials       16       16              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aklinker1 aklinker1 marked this pull request as ready for review February 3, 2024 20:55
@aklinker1 aklinker1 self-assigned this Feb 3, 2024
@aklinker1 aklinker1 added the bug Something isn't working label Feb 3, 2024
@aklinker1 aklinker1 changed the title fix: Don't crash service worker when referencing import.meta.url fix: Don't crash service worker when using import.meta.url Feb 3, 2024
@aklinker1 aklinker1 changed the title fix: Don't crash service worker when using import.meta.url fix: Don't crash background service worker when using import.meta.url Feb 3, 2024
@aklinker1 aklinker1 merged commit 66bd957 into main Feb 3, 2024
17 checks passed
@aklinker1 aklinker1 deleted the import-meta-url-fix branch February 3, 2024 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Background service worker : document is not defined
1 participant