Skip to content

Commit b48b830

Browse files
authored
ref: Access window.location first before trying document.location (#1180)
1 parent 2efb497 commit b48b830

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/raven.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,14 +1636,14 @@ Raven.prototype = {
16361636
};
16371637
}
16381638

1639-
if (this._hasDocument) {
1640-
if (_document.location && _document.location.href) {
1641-
httpData.url = _document.location.href;
1642-
}
1643-
if (_document.referrer) {
1644-
if (!httpData.headers) httpData.headers = {};
1645-
httpData.headers.Referer = _document.referrer;
1646-
}
1639+
// Check in `window` instead of `document`, as we may be in ServiceWorker environment
1640+
if (_window.location && _window.location.href) {
1641+
httpData.url = _window.location.href;
1642+
}
1643+
1644+
if (this._hasDocument && _document.referrer) {
1645+
if (!httpData.headers) httpData.headers = {};
1646+
httpData.headers.Referer = _document.referrer;
16471647
}
16481648

16491649
return httpData;

0 commit comments

Comments
 (0)