简体   繁体   中英

Using Sentry in Chrome Extension Background script not wroking

I have checked the official sentry docs and I have also checked out some other references but I can't find a solution...

Basically I am trying to install sentry in my browser extension.

So in my background.js I have done the following

import * as Sentry from '@sentry/browser';

Sentry.init({
  dsn: '...'
});

but... this isn't doing anything? - and it also seems to stop the rest of my code working, for example:

I have the following code in my background.js

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
    if (changeInfo.status === 'complete') {
      currentTab = tab;
      console.log(tab);
    }
  });

Now If I comment out the sentry init this code works as expected, but as soon as I put the sentry init back in, this code no longer runs.

I'm getting no errors, and I can't find any real examples of how to implement sentry with a browser extension. Now I know it's possible but I'm clearly doing something wrong?

I seem to have found the solution to my problem I was using a webpack to bundle my chrome-extension with required dependencies. Webpack was generating a vendor.js file which contained all the imported dependencies. In my case, the mistake I did was not adding that file the as scripts in the manifest.json file.

...
      "background": {
        "matches": ["https://*/*"],
        "scripts": ["js/vendor.js","js/background.js"],
        "persistent": true
      },
...

This resolved the issue as the dependencies are now loading correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM