Skip to content

Commit 38c7885

Browse files
mydeaantonpirker
authored andcommitted
fix(loader): Do not preprocess unhandled promise event in loader (#60077)
This is actually handled in the SDK, so we don't have to double process this. And the processing in the loader is error prone, because we do not guard for what `p` could be. I checked and even in v6 this was already checked in the SDK (e.g. see here from 2 years ago: https://github.com/getsentry/sentry-javascript/blob/4cd71c5792453d16acd0137af7534fe9345abd93/packages/browser/src/integrations/globalhandlers.ts) Also saving a few bytes ;) Closes getsentry/sentry-javascript#9579 Test in SDK added here: getsentry/sentry-javascript#9581
1 parent 53dd628 commit 38c7885

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

src/sentry/templates/sentry/js-sdk-loader.js.tmpl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,9 @@
4242
e: [].slice.call(arguments),
4343
});
4444
}
45-
function onUnhandledRejection(e) {
45+
function onUnhandledRejection(p) {
4646
enqueue({
47-
p: 'reason' in e
48-
? e.reason
49-
: 'detail' in e && 'reason' in e.detail
50-
? e.detail.reason
51-
: e,
47+
p: p,
5248
});
5349
}
5450
function onSentryCDNScriptLoaded() {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{% load sentry_helpers %}!function(n,e,t,r,i,o,a,c,s){for(var u=s,f=0;f<document.scripts.length;f++)if(document.scripts[f].src.indexOf(o)>-1){u&&"no"===document.scripts[f].getAttribute("data-lazy")&&(u=!1);break}var p=[];function d(n){return"e"in n}function l(n){return"p"in n}function _(n){return"f"in n}var v=[];function y(n){u&&(d(n)||l(n)||_(n)&&n.f.indexOf("capture")>-1||_(n)&&n.f.indexOf("showReportDialog")>-1)&&L(),v.push(n)}function h(){y({e:[].slice.call(arguments)})}function E(n){y({p:"reason"in n?n.reason:"detail"in n&&"reason"in n.detail?n.detail.reason:n})}function O(){try{n.SENTRY_SDK_SOURCE="loader";var e=n[i],o=e.init;e.init=function(i){n.removeEventListener(t,h),n.removeEventListener(r,E);var a=c;for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(a[s]=i[s]);!function(n,e){var t=n.integrations||[];if(!Array.isArray(t))return;var r=t.map((function(n){return n.name}));n.tracesSampleRate&&-1===r.indexOf("BrowserTracing")&&t.push(new e.BrowserTracing);(n.replaysSessionSampleRate||n.replaysOnErrorSampleRate)&&-1===r.indexOf("Replay")&&t.push(new e.Replay);n.integrations=t}(a,e),o(a)},setTimeout((function(){return function(e){try{"function"==typeof n.sentryOnLoad&&(n.sentryOnLoad(),n.sentryOnLoad=void 0);for(var t=0;t<p.length;t++)"function"==typeof p[t]&&p[t]();p.splice(0);for(t=0;t<v.length;t++){_(o=v[t])&&"init"===o.f&&e.init.apply(e,o.a)}g()||e.init();var r=n.onerror,i=n.onunhandledrejection;for(t=0;t<v.length;t++){var o;if(_(o=v[t])){if("init"===o.f)continue;e[o.f].apply(e,o.a)}else d(o)&&r?r.apply(n,o.e):l(o)&&i&&i.apply(n,[o.p])}}catch(n){console.error(n)}}(e)}))}catch(n){console.error(n)}}var m=!1;function L(){if(!m){m=!0;var n=e.scripts[0],t=e.createElement("script");t.src=a,t.crossOrigin="anonymous",t.addEventListener("load",O,{once:!0,passive:!0}),n.parentNode.insertBefore(t,n)}}function g(){var e=n.__SENTRY__;return!(void 0===e||!e.hub||!e.hub.getClient())}n[i]=n[i]||{},n[i].onLoad=function(n){g()?n():p.push(n)},n[i].forceLoad=function(){setTimeout((function(){L()}))},["init","addBreadcrumb","captureMessage","captureException","captureEvent","configureScope","withScope","showReportDialog"].forEach((function(e){n[i][e]=function(){y({f:e,a:arguments})}})),n.addEventListener(t,h),n.addEventListener(r,E),u||setTimeout((function(){L()}))}(window,document,"error","unhandledrejection","Sentry",'{{ publicKey|safe }}','{{ jsSdkUrl|safe }}',{{ config|to_json|safe }},{{ isLazy|safe|lower }});
1+
{% load sentry_helpers %}!function(n,e,t,r,i,o,a,c,u){for(var s=u,f=0;f<document.scripts.length;f++)if(document.scripts[f].src.indexOf(o)>-1){s&&"no"===document.scripts[f].getAttribute("data-lazy")&&(s=!1);break}var p=[];function d(n){return"e"in n}function l(n){return"p"in n}function _(n){return"f"in n}var v=[];function y(n){s&&(d(n)||l(n)||_(n)&&n.f.indexOf("capture")>-1||_(n)&&n.f.indexOf("showReportDialog")>-1)&&L(),v.push(n)}function h(){y({e:[].slice.call(arguments)})}function E(n){y({p:n})}function O(){try{n.SENTRY_SDK_SOURCE="loader";var e=n[i],o=e.init;e.init=function(i){n.removeEventListener(t,h),n.removeEventListener(r,E);var a=c;for(var u in i)Object.prototype.hasOwnProperty.call(i,u)&&(a[u]=i[u]);!function(n,e){var t=n.integrations||[];if(!Array.isArray(t))return;var r=t.map((function(n){return n.name}));n.tracesSampleRate&&-1===r.indexOf("BrowserTracing")&&t.push(new e.BrowserTracing);(n.replaysSessionSampleRate||n.replaysOnErrorSampleRate)&&-1===r.indexOf("Replay")&&t.push(new e.Replay);n.integrations=t}(a,e),o(a)},setTimeout((function(){return function(e){try{"function"==typeof n.sentryOnLoad&&(n.sentryOnLoad(),n.sentryOnLoad=void 0);for(var t=0;t<p.length;t++)"function"==typeof p[t]&&p[t]();p.splice(0);for(t=0;t<v.length;t++){_(o=v[t])&&"init"===o.f&&e.init.apply(e,o.a)}g()||e.init();var r=n.onerror,i=n.onunhandledrejection;for(t=0;t<v.length;t++){var o;if(_(o=v[t])){if("init"===o.f)continue;e[o.f].apply(e,o.a)}else d(o)&&r?r.apply(n,o.e):l(o)&&i&&i.apply(n,[o.p])}}catch(n){console.error(n)}}(e)}))}catch(n){console.error(n)}}var m=!1;function L(){if(!m){m=!0;var n=e.scripts[0],t=e.createElement("script");t.src=a,t.crossOrigin="anonymous",t.addEventListener("load",O,{once:!0,passive:!0}),n.parentNode.insertBefore(t,n)}}function g(){var e=n.__SENTRY__;return!(void 0===e||!e.hub||!e.hub.getClient())}n[i]=n[i]||{},n[i].onLoad=function(n){g()?n():p.push(n)},n[i].forceLoad=function(){setTimeout((function(){L()}))},["init","addBreadcrumb","captureMessage","captureException","captureEvent","configureScope","withScope","showReportDialog"].forEach((function(e){n[i][e]=function(){y({f:e,a:arguments})}})),n.addEventListener(t,h),n.addEventListener(r,E),s||setTimeout((function(){L()}))}(window,document,"error","unhandledrejection","Sentry",'{{ publicKey|safe }}','{{ jsSdkUrl|safe }}',{{ config|to_json|safe }},{{ isLazy|safe|lower }});

src/sentry/templates/sentry/js-sdk-loader.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,9 @@ declare const __LOADER__IS_LAZY__: any;
7676
});
7777
}
7878

79-
function onUnhandledRejection(e) {
79+
function onUnhandledRejection(p) {
8080
enqueue({
81-
p:
82-
'reason' in e
83-
? e.reason
84-
: 'detail' in e && 'reason' in e.detail
85-
? e.detail.reason
86-
: e,
81+
p,
8782
});
8883
}
8984

0 commit comments

Comments
 (0)