Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Don't call function multiple times on chrome.storage.sync.onChanged

I've made a chrome extension that block urls, defined in the extension's options.

I use declarativeNetRequest rules to handle the block list.

to reload the rules I listen for changes in the chrome.storage.sync

this works fine, but if I change more than one setting that I listen for the function "updateblocklist" will be triggered once for each setting that has been changed. This result in errors about the rule ids aren't unique since it's already taken, this is because the function will fire too quickly.

the updateblocklist remove all rules first and then add the blocked urls as rules.

background.js

chrome.storage.sync.onChanged.addListener(ps => {
    if (ps.list || ps.blocked || ps.homepage) {
        updateblocklist();
    }
});

So how can I still listen for multiple changes but only fire updateblocklist once?

I have the option of saving (clicking a button) or importing a json with the settings on my options page.

Importing json settings file:

chrome.storage.sync.clear(() => chrome.storage.sync.set(json, () => { location.reload();}))

Clicking save button:

chrome.storage.sync.set({
'list': document.getElementById('list').value,
'blocked': document.getElementById('blocked').value,
'homepage': document.getElementById('homepage').value
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!