getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.97k stars 1.57k forks source link

Cannot assign to read only property '__sentry__' of function... #4239

Closed wbobeirne closed 2 years ago

wbobeirne commented 2 years ago

Package + Version

Version:

6.15.0

Description

I have Sentry embedded in a javascript snippet that customers put on their own sites. It's worked fine everywhere except for one instance where they're getting this error on an XMLHttpRequest my script makes:

Cannot assign to read only property '__sentry__' of function 'function(){var r=Array.prototype.slice.call(arguments);try{n&&"function"==typeof n&&n.apply(this,arguments);var...<omitted>...}}'

Looks like that's from this wrapper:

https://github.com/getsentry/sentry-javascript/blob/8c77bb6a0b1602ffc7ad802938897cc63a26c67a/packages/browser/src/helpers.ts#L130-L146

Which wraps XMLHttpRequest here:

https://github.com/getsentry/sentry-javascript/blob/dcd549b4b50de32c3d532c65d7d6049061742f63/packages/browser/src/integrations/trycatch.ts#L97-L99

It seems like I could provide an option to disable wrapping of XMLHttpRequest, but I'd hate to do that for non-problematic installations. Could this property assignment instead by try / catch'd to avoid disruption?

Unfortunately I don't have the customer's code to determine what module they might be using that's causing XMLHttpRequest to already have this property as read-only, though I can only assume it's them also having Sentry installed. If that's the problem, is there a safe way to have two Sentry installations on one site?

AbhiPrasad commented 2 years ago

Hey thanks for writing in. We should guard against patching prototype's multiple times here: https://github.com/getsentry/sentry-javascript/blob/8c77bb6a0b1602ffc7ad802938897cc63a26c67a/packages/browser/src/helpers.ts#L53

Could you provide some kind of reproduction so we can investigate further?

wbobeirne commented 2 years ago

I'll see what I can rustle up, unfortunately this is only happening on an internal site so I don't have immediate access to the bundle that's causing this but I'll see if I can reproduce independently.

mitsuhiko commented 2 years ago

The entire property might be possible to remove. This PR removes it and should also fix this: https://github.com/getsentry/sentry-javascript/pull/4286

github-actions[bot] commented 2 years ago

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀