Attempting to create my first Chrome extension, focusing on blocking access to specific websites like Facebook or Instagram. Using code to close tabs if the blocked sites are accessed.
In a separate HTML file, providing users with two radio button options to block either Facebook or Instagram.
Encountering an error on line 9 when attempting to load the extension in Chrome:
"Uncaught TypeError: Error in invocation of storage.set(object items, optional function callback): No matching signature."
Struggling to comprehend explanations found online due to being new to coding. Seeking assistance to proceed forward!
CODE:
document.addEventListener('DOMContentLoaded', function() {
selectCurrentValues();
let saveButton = document.getElementById('save');
if(saveButton) {
saveButton.addEventListener('click', function() {
let closingMethodRadios = document.getElementsByName('blockingMethod');
if(closingMethodRadios[0].checked){
chrome.storage.sync.set({'blockingMethod': "close_tab"},
chrome.webRequest.onBeforeRequest.addListener(
function(details) { return { cancel: true }},
{ urls: ["*://*.facebook.com/*"]},
["blocking"]
),
function() {
console.log('Closing tab set.');
});
}
else if(closingMethodRadios[1].checked){
chrome.storage.sync.set({'blockingMethod': "close_tab"},
chrome.webRequest.onBeforeRequest.addListener(
function(details) { return { cancel: true }},
{ urls: ["*://*.instagram.com/*"]},
["blocking"]
),
function() {
console.log('Closing tab set.');
});
}
});
}});
function selectCurrentValues(){
chrome.storage.sync.get('blockingMethod', function (data){
switch(data.blockingMethod){
case "close_tab":
document.getElementById("close_tab").checked = true;
break;
case "clear_tab":
document.getElementById("clear_tab").checked = true;
break;
}
});
}