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

128
Views
Is there a way to update a variable outside an event listener using that listener?

I have a situation where I have a variable in cloud storage, that I am fetching asynchronously every time I want to do something with it. Currently the code looks like this:

chrome.tabs.onUpdated.addListener(function() {
        // Fetch example_variable from storage, then
        // Do things with example_variable...
});

chrome.tabs.onActivated.addListener(function() {
        // Fetch example_variable from storage, then
        // Do things with example_variable...
});

Since fetching the example_variable from the cloud every time the events trigger (it can happen more than a dozen times per minute) is very inefficient, I was thinking about restructuring it like this:

chrome.storage.onChanged.addListener(function() { // Everytime the cloud variable changes
        // Fetch example_variable from storage, then
        // set example_variable to what I fetched.
});

chrome.tabs.onUpdated.addListener(function() {
        // Do things with example_variable...
});

chrome.tabs.onActivated.addListener(function() {
        // Do things with example_variable...
});

My first thought was to create new listeners inside of the storage update listener (and close the old ones), but the Chrome Extension documentation directly warns against this.

I could use globally-scoped variables, but that seems incredibly janky and inelegant.

I'd appreciate any help!

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!