🐛 [RUM-11848] Guard window/location access for non-browser environments#4674
Merged
Conversation
Bundles Sizes Evolution
|
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: bec77f6 | Docs | Datadog PR Page | Give us feedback! |
41392e6 to
7884e3d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7884e3df33
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
thomas-lebeau
approved these changes
May 28, 2026
gogusarov
approved these changes
May 28, 2026
7884e3d to
984726c
Compare
mormubis
commented
May 28, 2026
Comment on lines
+84
to
+86
| if (typeof document === 'undefined') { | ||
| return undefined | ||
| } |
Contributor
Author
There was a problem hiding this comment.
I needed to add this bit to actually fix the codex p2.
984726c to
bec77f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The SDK crashes with
ReferenceError: location is not definedandwindow is not definedwhen initialized in Web Workers or Node.js. Three code paths access browser globals without guards:normalizeUrl()uses barelocation.href,storeContextManager()uses barewindowandlocalStorage, andgetCurrentSite()useslocation.hostnamein a default parameter.~107 telemetry errors/week across v6.21.x and v7.1.0. Telemetry link.
Relates to RUM-11848.
Changes
Each function now handles non-browser environments gracefully instead of crashing:
normalizeUrl()usesglobalObject.location?.hrefas base URL. For absolute URLs (the common case withproxy), the base is ignored anyway.storeContextManager()returns early whenwindoworlocalStorageare unavailable. It becomes a silent no-op in workers/Node.getCurrentSite()uses safe defaults forhostnameandreferrerparameters instead of barelocation/documentaccess.Test instructions
yarn devExpected:
{ status: 'ok' }. Without the fix:ReferenceError: window is not defined.Checklist