From 0ecc124b24164f7e7aee06ed21db9c5eb5d1a128 Mon Sep 17 00:00:00 2001 From: Ian Bicking Date: Thu, 3 Oct 2019 15:42:46 -0500 Subject: [PATCH] Make Sentry work properly in the popup and recorder pages This lazy-loads sentry.js in those contexts. --- extension/catcher.js | 13 ++++++++++--- extension/catcherAsyncSetup.js | 5 +++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 extension/catcherAsyncSetup.js diff --git a/extension/catcher.js b/extension/catcher.js index f07861598..996ef179a 100644 --- a/extension/catcher.js +++ b/extension/catcher.js @@ -1,4 +1,4 @@ -/* globals Sentry, buildSettings */ +/* globals Sentry, buildSettings, catcherAsyncSetup */ this.catcher = (function() { const exports = {}; @@ -17,7 +17,8 @@ this.catcher = (function() { if (!buildSettings.sentryDsn) { return; } - Sentry.init({ + const sentryOptions = { + url: "/js/vendor/sentry.js", dsn: buildSettings.sentryDsn, release: manifest.version, environment: buildSettings.channel, @@ -39,7 +40,13 @@ this.catcher = (function() { } return event; }, - }); + }; + if (typeof Sentry === "undefined") { + window.SENTRY_DSK = sentryOptions; + catcherAsyncSetup(); + } else { + Sentry.init(sentryOptions); + } } exports.capture = function(e) { diff --git a/extension/catcherAsyncSetup.js b/extension/catcherAsyncSetup.js new file mode 100644 index 000000000..657637873 --- /dev/null +++ b/extension/catcherAsyncSetup.js @@ -0,0 +1,5 @@ +/* eslint-disable */ +// Note this has to be a separate file since it shouldn't get automatically formatted +this.catcherAsyncSetup = function() { + ;(function(a,b,g,e,h){var k=a.SENTRY_SDK,f=function(a){f.data.push(a)};f.data=[];var l=a[e];a[e]=function(c,b,e,d,h){f({e:[].slice.call(arguments)});l&&l.apply(a,arguments)};var m=a[h];a[h]=function(c){f({p:c.reason});m&&m.apply(a,arguments)};var n=b.getElementsByTagName(g)[0];b=b.createElement(g);b.src=k.url;b.crossorigin="anonymous";b.addEventListener("load",function(){try{a[e]=l;a[h]=m;var c=f.data,b=a.Raven;b.config(k.dsn,k.options).install();var g=a[e];if(c.length)for(var d=0;d