-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(chrome-extension): update example to include content and backgr…
…ound scripts (#1409)
- Loading branch information
Showing
10 changed files
with
79 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
/* eslint-disable no-undef */ | ||
// background.js | ||
importScripts(chrome.runtime.getURL('vendor/honeybadger.ext.min.js')); | ||
importScripts(chrome.runtime.getURL('error-reporting.js')); | ||
|
||
let color = '#3aa757'; | ||
|
||
chrome.runtime.onInstalled.addListener(() => { | ||
chrome.storage.sync.set({ color }); | ||
console.log('Default background color set to %cgreen', `color: ${color}`); | ||
}); | ||
// in order to catch errors in listeners, we have to wrap them in a try-catch block | ||
try { | ||
chrome.storage.sync.set({ color }); | ||
console.log('Default background color set to %cgreen', `color: ${color}`); | ||
|
||
// You can now use Honeybadger functions here | ||
if (typeof globalThis.Honeybadger !== 'undefined') { | ||
somethingUndefinedInBackgroundScript(); // This will throw an error | ||
} | ||
else { | ||
console.log('[background.js] Honeybadger is not loaded.'); | ||
} | ||
} | ||
catch (error) { | ||
if (typeof globalThis.Honeybadger !== 'undefined') { | ||
globalThis.Honeybadger.notify(error); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
console.log('[content.js] Hello from content.js'); | ||
|
||
if (typeof window.Honeybadger !== 'undefined') { | ||
console.log('[content.js] Honeybadger is loaded.'); | ||
} | ||
|
||
// eslint-disable-next-line no-undef | ||
somethingUndefined(); // This will throw an error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
// eslint-disable-next-line no-undef | ||
Honeybadger.configure({ | ||
apiKey: 'YOUR_API_KEY', | ||
environment: 'production' | ||
}); | ||
/* eslint-disable no-undef */ | ||
if (typeof globalThis.Honeybadger !== 'undefined') { | ||
globalThis.Honeybadger.configure({ | ||
apiKey: 'API_KEY', | ||
environment: 'chrome-extension', | ||
debug: true | ||
}); | ||
console.log('[error-reporting.js] Honeybadger is configured.'); | ||
} | ||
else { | ||
console.log('[error-reporting.js] Honeybadger is not loaded.'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
|
||
curl -o vendor/honeybadger.min.js https://js.honeybadger.io/v6.9/honeybadger.ext.min.js | ||
curl -o vendor/honeybadger.ext.min.js https://js.honeybadger.io/v6.10/honeybadger.ext.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
honeybadger.min.js | ||
honeybadger.min.js | ||
honeybadger.ext.min.js |