Skip to content

fix(browser): Improve browser extension error message check #12146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2024

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented May 21, 2024

This PR makes our check for when we abort and log an error due to Sentry.init being used in a browser extension a bit more fine-gained. In particular, we now do not abort the SDK initialization if we detect that the SDK is running in a browser-extension dedicated window (e.g. a URL starting with chrome-extension://).

This was raised in #12025. h/t @Thomas101 for providing the initial idea how to check for the dedicated pages. I expanded on the check a bit to add other browsers. This list is not complete but probably good enough for start.

Also rewrote the function a bit to hopefully save a few bytes 🤞

@Lms24 Lms24 marked this pull request as ready for review May 21, 2024 15:41
@Lms24 Lms24 requested review from a team, lforst, s1gr1d and AbhiPrasad and removed request for a team May 21, 2024 15:41
@mydea mydea force-pushed the lms/fix-browser-extension-detection branch from 23e966a to ed286fd Compare May 22, 2024 08:36
return !!isInsideBrowserExtension || !!isInsideChromeExtension;
const windowWithMaybeExtension = WINDOW as typeof WINDOW & ExtensionProperties;

const extensionKey = windowWithMaybeExtension.chrome ? 'chrome' : 'browser';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to clarify, when would you have window.browser.xxx, and would that mean this is an extension??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we introduced this in the original browser extension check (https://github.com/getsentry/sentry-javascript/pull/10844/files)

Copy link
Contributor

size-limit report 📦

Path Size
@sentry/browser 21.76 KB (+0.18% 🔺)
@sentry/browser (incl. Tracing) 32.92 KB (+0.13% 🔺)
@sentry/browser (incl. Tracing, Replay) 68.27 KB (+0.07% 🔺)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 61.66 KB (+0.08% 🔺)
@sentry/browser (incl. Tracing, Replay with Canvas) 72.31 KB (+0.07% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) 84.34 KB (+0.06% 🔺)
@sentry/browser (incl. Feedback) 37.76 KB (+0.14% 🔺)
@sentry/browser (incl. sendFeedback) 26.33 KB (+0.16% 🔺)
@sentry/browser (incl. FeedbackAsync) 30.74 KB (+0.16% 🔺)
@sentry/react 24.45 KB (+0.18% 🔺)
@sentry/react (incl. Tracing) 35.9 KB (+0.1% 🔺)
@sentry/vue 25.71 KB (+0.21% 🔺)
@sentry/vue (incl. Tracing) 34.73 KB (+0.11% 🔺)
@sentry/svelte 21.89 KB (+0.18% 🔺)
CDN Bundle 24.31 KB (+0.18% 🔺)
CDN Bundle (incl. Tracing) 34.36 KB (+0.14% 🔺)
CDN Bundle (incl. Tracing, Replay) 68.05 KB (+0.07% 🔺)
CDN Bundle (incl. Tracing, Replay, Feedback) 73.05 KB (+0.07% 🔺)
CDN Bundle - uncompressed 71.43 KB (+0.14% 🔺)
CDN Bundle (incl. Tracing) - uncompressed 101.84 KB (+0.1% 🔺)
CDN Bundle (incl. Tracing, Replay) - uncompressed 211.46 KB (+0.05% 🔺)
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 223.81 KB (+0.05% 🔺)
@sentry/nextjs (client) 35.13 KB (+0.12% 🔺)
@sentry/sveltekit (client) 33.49 KB (+0.1% 🔺)
@sentry/node 128.41 KB (+0.13% 🔺)
@sentry/aws-serverless 114.42 KB (+0.13% 🔺)

@Lms24 Lms24 self-assigned this May 27, 2024
@Lms24 Lms24 merged commit 8dca102 into develop May 27, 2024
95 checks passed
@Lms24 Lms24 deleted the lms/fix-browser-extension-detection branch May 27, 2024 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants