On the Options page, clicking on a setting generates the following error in the debug console:
Strangely, the line number isn’t specified!
This code handles the checkbox click in options.js:
function updateTabMode() {
if (sameTab.checked || openSidebar.checked) {
active.style.visibility = "hidden";
} else {
active.style.visibility = "visible";
}
let data = {};
data["tabMode"] = document.querySelector('input[name="results"]:checked').value;
data["tabActive"] = tabActive.checked;
sendMessage("updateTabMode", data);
}
and the following code should handle the message received in background.js from options.js:
browser.runtime.onMessage.addListener(handleMessages);
async function handleMessages(message, sender, sendResponse) {
let id = "";
let domain = "";
switch (message.action) {
case "updateTabMode": {
const settings = await getOptions();
let options = settings.options;
if (logToConsole) console.log(`Preferences retrieved from storage sync: ${JSON.stringify(options)}`);
options.tabMode = message.data.tabMode;
options.tabActive = message.data.tabActive;
setTabMode(options);
await saveOptions(options, false);
break;
}
When I define getOptions as follows, the code works:
async function getOptions(){
return new Promise(
(resolve, reject) => {
browser.storage.sync.get(null).then(resolve, reject);
}
);
}
It failed previously with getOptions defined as follows:
async function getOptions(){
try {
let data = await browser.storage.sync.get("options");
if (logToConsole) console.log(JSON.stringify(data));
return data;
} catch (err) {
if (logToConsole) {
console.error(err);
console.log("Failed to retrieve options from storage sync.");
}
}
}
What is the reason for the second async version failing?