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.
This makes us defensive against
window
not existing so we can work in webworkers. Should fix #784 and #747, though there are some things to figure out/change before merging.The reason for big 4-branch
_window
thing is that in web workers,self
is a sort-of-global-object-thing, and in Nodeglobal
is the global object (not that we need raven-js to work in node, but I was testing a few things with it as an easy env that doesn't havewindow
). If none of them exist, I fall back to an empty object rather than doing something likeFunction('return this')()
(CSP issues) or(function () { return this; })()
(strict mode issues); I'm pretty sure all of our uses of_window
still turn out okay in that case, but we won't properly instrumentsetTimeout
andsetInterval
. I'm not too worried about that case, though.I'm not sure what the best approach is gonna be to making tracekit not blow up here; obviously we don't just wanna hand edit it to be defensive every time we update our vendor copy of tracekit (like I've done in this PR just to prove things work). I don't think we can pull off any sort of slick trick where we just make the
window
reference TraceKit uses actually be something we provide like our_window
. Not sure if it makes sense for us to send them a PR to make it defensive, but I guess the webworker use case could be motivating; it looks like the current code at https://github.com/csnover/TraceKit toucheswindow
a lot more than our current version, though, and I'm not really familiar with our usage of it/interest in updating./cc @MaxBittker @benvinegar