Skip to content

Commit ef59a91

Browse files
committed
fix(browser): Don't use chrome variable name (#10874)
resolves #6880 Using `const chrome = ...` or similar breaks certain setups based on their bundler config. This makes changes to browser code so that we never declare a variable named `chrome`. I tried setting up https://eslint.org/docs/latest/rules/id-denylist to enforce this, but this unfortunately also looks as types declarations (so `type K = { chrome: ... }` is problematic.
1 parent 3c841ce commit ef59a91

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/browser/src/stack-parsers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ const chromeRegex =
5858
/^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
5959
const chromeEvalRegex = /\((\S*)(?::(\d+))(?::(\d+))\)/;
6060

61-
const chrome: StackLineParserFn = line => {
61+
// We cannot call this variable `chrome` because it can conflict with global `chrome` variable in certain environments
62+
// See: https://github.com/getsentry/sentry-javascript/issues/6880
63+
const chromeStackParserFn: StackLineParserFn = line => {
6264
const parts = chromeRegex.exec(line);
6365

6466
if (parts) {
@@ -85,7 +87,7 @@ const chrome: StackLineParserFn = line => {
8587
return;
8688
};
8789

88-
export const chromeStackLineParser: StackLineParser = [CHROME_PRIORITY, chrome];
90+
export const chromeStackLineParser: StackLineParser = [CHROME_PRIORITY, chromeStackParserFn];
8991

9092
// gecko regex: `(?:bundle|\d+\.js)`: `bundle` is for react native, `\d+\.js` also but specifically for ram bundles because it
9193
// generates filenames without a prefix like `file://` the filenames in the stacktrace are just 42.js

packages/utils/src/vendor/supportsHistory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export function supportsHistory(): boolean {
3838
// borrowed from: https://github.com/angular/angular.js/pull/13945/files
3939
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
4040
// eslint-disable-next-line @typescript-eslint/no-explicit-any
41-
const chrome = (WINDOW as any).chrome;
42-
const isChromePackagedApp = chrome && chrome.app && chrome.app.runtime;
41+
const chromeVar = (WINDOW as any).chrome;
42+
const isChromePackagedApp = chromeVar && chromeVar.app && chromeVar.app.runtime;
4343
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
4444
const hasHistoryApi = 'history' in WINDOW && !!WINDOW.history.pushState && !!WINDOW.history.replaceState;
4545

0 commit comments

Comments
 (0)