Repository navigation
fix(entrypoint-loader): define location in the entrypoint environment - #2611
Conversation
The inline environment used to evaluate entrypoints gives LinkeDOM's window and document but no location. A dependency that detects a browser from those two then reads window.location while its module initializes and throws, so wxt prepare fails before it can generate types. Axios 1.18.1 is a minimal case: it reads window.location.href and dies with "Cannot read properties of undefined (reading 'href')". Define an inert location on window, on the LinkeDOM global and on globalThis. It is a read-only stand-in pointing at http://localhost/; there is no page to navigate at build time, so assign, reload and replace do nothing rather than throw.
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@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: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2611 +/- ##
==========================================
+ Coverage 79.57% 79.60% +0.03%
==========================================
Files 138 138
Lines 4102 4114 +12
Branches 943 943
==========================================
+ Hits 3264 3275 +11
- Misses 739 741 +2
+ Partials 99 98 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-authored-by: Aaron <aaronklinker1@gmail.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
|
Thanks for helping make WXT better! |
Closes #2601.
What was wrong
getBrowserEnvironmentGlobalshands entrypoint evaluation LinkeDOM'swindowanddocument, but nolocation. Confirmed against linkedom 0.18.13:That is the worst combination for browser-detecting dependencies. They check
typeof window !== 'undefined' && typeof document !== 'undefined', conclude they are in a browser, and then readwindow.locationwhile the module is still initializing. Axios 1.18.1 does exactly this, andwxt preparedies before it can generate types, with the error above.The fix
Define an inert
locationonwindow, on the LinkeDOMglobal(soself.locationresolves too), and in the returned globals soapplyGlobalsputs it onglobalThis.It is a read-only stand-in pointing at
http://localhost/, carrying the fields detection code actually reads:href,protocol,host,hostname,origin,port,pathname,search,hash, plustoString. There is no page to navigate at build time, soassign,reloadandreplaceare no-ops rather than throwing.A plain
URLwas the obvious choice and does not typecheck:window.locationis typedstring & Location, andURLis missingancestorOrigins,assign,reloadandreplace. Hence the smallLocation-shaped helper and one narrow cast at thewindow.locationassignment, which nothing can satisfy honestly.Testing
New
browser-environment.test.ts, 4 tests. All 4 pass with the change and all 4 fail without it, the key one failing with the issue's exact error:One of them reproduces the real shape of the bug rather than just asserting the field exists: it runs inside
env.run, assertshasBrowserEnvis true, and then readswindow.location.href.Full
packages/wxtsuite on Windows: 52 files passed, 550 tests passed, 4 skipped, 2 todo, 0 failed.tsc --noEmitis clean andprettier --checkpasses on both files.Worth flagging honestly: an earlier full-suite run showed
e2e/tests/wxt.test.tsfailing withEADDRINUSE ... ::1:3000. That test deliberately occupies port 3000, it passed twice in isolation with this change applied, it passed on a baseline run, and the final full run above is green. It was leaked processes from my repeated runs, not this diff.Not verified
I did not run the gist reproduction end to end with axios installed; the tests above model the same failure directly against the environment. I also have not checked the extension environment path beyond it reusing
getBrowserEnvironmentGlobals.Happy to change the placeholder URL if you would rather it were something else, or make it configurable.
AI usage
Claude Code (Claude Opus 5) helped investigate and write this; I reviewed the diff and ran everything above myself.