MindscapeHQ / raygun4js

JavaScript provider for Raygun
https://raygun.com
Other
149 stars 60 forks source link

Cant report errors from a chrome extension? #453

Closed mikecann closed 2 years ago

mikecann commented 2 years ago

Hi im trying to setup raygun in my chrome extension.

It works from a website fine but for some reason not in the extension.

Im using the npm version of raygun4js.

At first I thought it was somehow filtering it out thanks to this line: https://github.com/MindscapeHQ/raygun4js/blob/3c07dc178ca34adaacae7fbd9efe6550e21da18b/src/raygun.js#L1140

But when I added some debug console lines around it I found out that its not event getting to that part and is instead exiting the function here: https://github.com/MindscapeHQ/raygun4js/blob/dd4bf9808ccf570ddc271f2239596159bb61344b/src/raygun.js#L706

It appears that the _providerState !== ProviderStates.READY .. any idea why this might be? Im not getting any errors from raygun despite having set debugMode: true perhaps this is because I set debugMode: true AFTER the init error?!

mikecann commented 2 years ago

After more node_modules/raygun4js/dist/raygun.umd.js spelunking I managed to track it down and get it working.

It appears that there is an order of operations issue happening where onLoadHandler is looking for apiKey to be set but it hasnt by that point so rg.init never gets called.

I fixed this by manually initting:

 const instance = rg4js("getRaygunInstance") as any;
    if (instance)
      instance.init(
        config.BT_RAYGUN_API_KEY,
        {
          ignore3rdPartyErrors: false,
          debugMode: true,
        },
        null
      );

hacky but works.