Skip to content

Commit 30ea755

Browse files
authored
ref(browser): Remove optional chaining (#4290)
1 parent 0f49c02 commit 30ea755

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

packages/browser/src/integrations/trycatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export class TryCatch implements Integration {
232232
*/
233233
const wrappedEventHandler = (fn as unknown) as WrappedFunction;
234234
try {
235-
const originalEventHandler = wrappedEventHandler?.__sentry_wrapped__;
235+
const originalEventHandler = wrappedEventHandler && wrappedEventHandler.__sentry_wrapped__;
236236
if (originalEventHandler) {
237237
originalRemoveEventListener.call(this, eventName, originalEventHandler, options);
238238
}

packages/browser/src/integrations/useragent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ export class UserAgent implements Integration {
2828
}
2929

3030
// grab as much info as exists and add it to the event
31-
const url = event.request?.url || global.location?.href;
31+
const url = (event.request && event.request.url) || (global.location && global.location.href);
3232
const { referrer } = global.document || {};
3333
const { userAgent } = global.navigator || {};
3434

3535
const headers = {
36-
...event.request?.headers,
36+
...(event.request && event.request.headers),
3737
...(referrer && { Referer: referrer }),
3838
...(userAgent && { 'User-Agent': userAgent }),
3939
};

packages/browser/src/transports/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ export function getNativeFetchImplementation(): FetchImpl {
5858
const document = global.document;
5959
let fetchImpl = global.fetch;
6060
// eslint-disable-next-line deprecation/deprecation
61-
if (typeof document?.createElement === `function`) {
61+
if (document && typeof document.createElement === `function`) {
6262
try {
6363
const sandbox = document.createElement('iframe');
6464
sandbox.hidden = true;
6565
document.head.appendChild(sandbox);
66-
if (sandbox.contentWindow?.fetch) {
67-
fetchImpl = sandbox.contentWindow.fetch;
66+
const contentWindow = sandbox.contentWindow;
67+
if (contentWindow && contentWindow.fetch) {
68+
fetchImpl = contentWindow.fetch;
6869
}
6970
document.head.removeChild(sandbox);
7071
} catch (e) {

0 commit comments

Comments
 (0)