From 996501642bd0d85700870f78d403c88f18979740 Mon Sep 17 00:00:00 2001 From: Gabriel Aubut-Lussier Date: Fri, 9 Feb 2024 11:49:23 -0500 Subject: [PATCH 1/3] Fix the storage.sync part of the example with Firefox on macOS when managed storage isn't available. --- favourite-colour/options.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/favourite-colour/options.js b/favourite-colour/options.js index 542fa1e9..6da4a15a 100644 --- a/favourite-colour/options.js +++ b/favourite-colour/options.js @@ -6,8 +6,12 @@ async function saveOptions(e) { } async function restoreOptions() { - let res = await browser.storage.managed.get('colour'); - document.querySelector("#managed-colour").innerText = res.colour; + try { + let res = await browser.storage.managed.get('colour'); + document.querySelector("#managed-colour").innerText = res.colour; + } catch(error) { + console.log(JSON.stringify(error)); + } res = await browser.storage.sync.get('colour'); document.querySelector("#colour").value = res.colour || 'Firefox red'; From 83dba4f671d820f24eb74ba994de1487e9ab663c Mon Sep 17 00:00:00 2001 From: rebloor Date: Fri, 1 Nov 2024 14:35:21 +1300 Subject: [PATCH 2/3] Suggestion from feedback Co-authored-by: Simeon Vincent --- favourite-colour/options.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/favourite-colour/options.js b/favourite-colour/options.js index 6da4a15a..73d45824 100644 --- a/favourite-colour/options.js +++ b/favourite-colour/options.js @@ -6,12 +6,16 @@ async function saveOptions(e) { } async function restoreOptions() { - try { - let res = await browser.storage.managed.get('colour'); - document.querySelector("#managed-colour").innerText = res.colour; - } catch(error) { - console.log(JSON.stringify(error)); - } + try { + let res = await browser.storage.managed.get('colour'); + document.querySelector("#managed-colour").innerText = res.colour || "Could not find 'colour' in managed storage."; + } catch(error) { + if (error.message === "Managed storage manifest not found") { + document.querySelector("#managed-colour").innerText = "Managed storage manifest not found. Make sure it's stored in an appropriate location."; + } else { + document.querySelector("#managed-colour").innerText = `Unexpected managed storage error: ${error.message}`; + } + } res = await browser.storage.sync.get('colour'); document.querySelector("#colour").value = res.colour || 'Firefox red'; From 3e189c89652ab922496842af7eae35ba973d499d Mon Sep 17 00:00:00 2001 From: Simeon Vincent Date: Wed, 5 Nov 2025 18:52:13 -0800 Subject: [PATCH 3/3] Normalize indentation --- favourite-colour/options.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/favourite-colour/options.js b/favourite-colour/options.js index 73d45824..f929640f 100644 --- a/favourite-colour/options.js +++ b/favourite-colour/options.js @@ -6,16 +6,16 @@ async function saveOptions(e) { } async function restoreOptions() { - try { - let res = await browser.storage.managed.get('colour'); - document.querySelector("#managed-colour").innerText = res.colour || "Could not find 'colour' in managed storage."; - } catch(error) { - if (error.message === "Managed storage manifest not found") { - document.querySelector("#managed-colour").innerText = "Managed storage manifest not found. Make sure it's stored in an appropriate location."; - } else { - document.querySelector("#managed-colour").innerText = `Unexpected managed storage error: ${error.message}`; - } - } + try { + let res = await browser.storage.managed.get('colour'); + document.querySelector("#managed-colour").innerText = res.colour || "Could not find 'colour' in managed storage."; + } catch(error) { + if (error.message === "Managed storage manifest not found") { + document.querySelector("#managed-colour").innerText = "Managed storage manifest not found. Make sure it's stored in an appropriate location."; + } else { + document.querySelector("#managed-colour").innerText = `Unexpected managed storage error: ${error.message}`; + } + } res = await browser.storage.sync.get('colour'); document.querySelector("#colour").value = res.colour || 'Firefox red';