Add fallback to globalThis if window and global undefined#123
Conversation
drfuzzyness
left a comment
There was a problem hiding this comment.
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 |
|
@austintheriotgl really sorry for the delay. I just had time to get the ci partially updated and building again. |
|
Thanks for merging this, @niemyjski! Could we get a release out with the fix, so that I can bump the version in the Honeycomb SDK? |
|
I'll try and get this pushed |
|
Pushed :) |


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.