Log errors

This commit is contained in:
Juhani Krekelä 2024-07-25 17:15:54 +03:00
parent b2390e5b54
commit c59a28c126

View file

@ -3,6 +3,13 @@ if (window.browser === undefined) {
window.browser = window.chrome; window.browser = window.chrome;
} }
function errorLogger(action) {
function log(error) {
console.log(`Error: ${action}:`, error);
}
return log;
}
function createRedirect(id, from, transform) { function createRedirect(id, from, transform) {
return { return {
id: id, id: id,
@ -32,7 +39,7 @@ function updateRedirects(settings) {
redirects.push(createRedirect(1, '||twitter.com', transform)); redirects.push(createRedirect(1, '||twitter.com', transform));
redirects.push(createRedirect(2, '||x.com', transform)); redirects.push(createRedirect(2, '||x.com', transform));
} }
browser.declarativeNetRequest.updateDynamicRules({ return browser.declarativeNetRequest.updateDynamicRules({
addRules: redirects, addRules: redirects,
removeRuleIds: [1, 2], removeRuleIds: [1, 2],
}); });
@ -55,8 +62,11 @@ function setupSettingsForm(settings) {
settings.instance = instance.value; settings.instance = instance.value;
settings.username = username.value; settings.username = username.value;
settings.password = password.value; settings.password = password.value;
browser.storage.local.set(settings); browser.storage.local.set(settings)
updateRedirects(settings); .then(
() => updateRedirects(settings),
errorLogger('browser.storage.local.set')
).catch(errorLogger('updateRedirects'));
}); });
} }
} }
@ -66,4 +76,4 @@ browser.storage.local.get({
instance: '', instance: '',
username: '', username: '',
password: '', password: '',
}).then(setupSettingsForm); }).then(setupSettingsForm, errorLogger('browser.storage.local.get'));