Skip to content
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

fix(browser): Check for existence of instrumentation targets #8939

Merged
merged 4 commits into from
Sep 5, 2023
Merged

fix(browser): Check for existence of instrumentation targets #8939

merged 4 commits into from
Sep 5, 2023

Conversation

SorsOps
Copy link
Contributor

@SorsOps SorsOps commented Sep 4, 2023

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • [ x ] If you've added code that should be tested, please add tests.
  • [ x ] Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

Description

There are cases when global objects such as the window object are shimmed that they define properties such as document, but the actual value is undefined. This exact situation has been occurring and is causing the instrumentDOM function to throw an error as 'document' in WINDOW is technically true though the value is falsey. We should rather attempt an actual check of the value being truthy rather than if the property is defined

@lforst lforst self-requested a review September 4, 2023 12:14
@lforst lforst changed the title Fix issue with instrumentation when values are falsey fix(browser): Check for existence of instrumentation targets Sep 4, 2023
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Thanks for opening this PR! LGTM.

function instrumentXHR(): void {
if (!('XMLHttpRequest' in WINDOW)) {
export function instrumentXHR(): void {
if (!(WINDOW as any).XMLHttpRequest) {
Copy link
Member

Choose a reason for hiding this comment

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

q: Why do we need the typecast to any here? Or IOW why do we need it here and not in WINDOW.document below?

Copy link
Member

Choose a reason for hiding this comment

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

ignore this, just learned that it's not in WINDOW. Makes sense!

@Lms24
Copy link
Member

Lms24 commented Sep 5, 2023

Btw, our linter (yarn lint) complains about the any usage:

/home/runner/work/sentry-javascript/sentry-javascript/packages/utils/src/instrument.ts
  251:8  error  Unsafe member access .XMLHttpRequest on an `any` value  @typescript-eslint/no-unsafe-member-access

If there's no way around it, feel free to disable the rule for this line.

@Lms24 Lms24 merged commit ef51993 into getsentry:develop Sep 5, 2023
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.

3 participants