-
Notifications
You must be signed in to change notification settings - Fork 161
Add fallback to globalThis if window and global undefined
#123
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
base: master
Are you sure you want to change the base?
Conversation
drfuzzyness
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than remove the window check, would it be better to add to the ternary chain to check if global is defined, then fall back to globalThis? Just using globalThis is a JS feature from 2020 and this library targets platforms from the 2000s.
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#browser_compatibility
[2] https://github.com/csnover/TraceKit#supports-all-major-browsers-from-ie6-to-opera-the-android-webview-and-everywhere-in-between
|
Thanks @drfuzzyness, that seems reasonable to me, so long as the expression
Updated the PR with your suggestion. |
|
This is failing in CI for reasons that appear unrelated to my changes:
https://github.com/csnover/TraceKit/actions/runs/19046314393/job/54479505479?pr=123 |
|
Can you please merge in master to see if the updated ci works. We really need to move off grunt and jasmine. Would love a pr for that if anyone is reading this |
|
@niemyjski Just merged in master 👍 |
window and global keywords with globalThisglobalThis if window and global undefined
|
Hey all, is there anything you need from me to move this along? I see that CI is still failing |


This PR attempts to fix this error here: #122
It keeps the original
windowkeyword for backwards compatibility for older browsers, adds a check if theglobalkeyword is defined (it is in Node environments, but not in browser contexts), then falls back toglobalThisif the other two are not defined, which should allow it to work in Web Worker contexts.