mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
31 lines
642 B
JavaScript
31 lines
642 B
JavaScript
// Polyfill the "browser" global in Chrome.
|
|
globalThis.browser ??= chrome;
|
|
|
|
/*
|
|
Default settings. Initialize storage to these values.
|
|
*/
|
|
let authCredentials = {
|
|
username: "user",
|
|
password: "passwd"
|
|
}
|
|
|
|
/*
|
|
Generic error logger.
|
|
*/
|
|
function onError(e) {
|
|
console.error(e);
|
|
}
|
|
|
|
/*
|
|
On startup, check whether we have stored settings.
|
|
If we don't, then store the default settings.
|
|
*/
|
|
function checkStoredSettings(storedSettings) {
|
|
if (!storedSettings.authCredentials) {
|
|
browser.storage.local.set({authCredentials});
|
|
}
|
|
}
|
|
|
|
const gettingStoredSettings = browser.storage.local.get();
|
|
gettingStoredSettings.then(checkStoredSettings, onError);
|