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

301
Views
CHROME - EXTENSIONS: chrome.webRequest.onBeforeRequest does not finish the process?

I am working on a project which produces a google extension. In my extension, I tried to access resources of a website. Here is my code

 if (requestArray.length !== 0) {
    requestArray = []
  }
  if (resourcesCategories.length !== 0) {
    resourcesCategories = []
  }
  if (mywebsiteCategories.length !== 0) {
    mywebsiteCategories = []
  }

  getWebsiteCategories().then((webCat) => {
    if (webCat.length !== 0) {
      setWebsiteCategories([])
    }
  })

  getResourcesCategories().then((resCat) => {
    if (resCat.length !== 0) {
      setResourcesCategories([])
    }
  })
  getResources().then((res) => {
    if (res.length !== 0) {
      setResources([])
    }
  })
  chrome.webRequest.onBeforeRequest.addListener(
    (details) => {
      if (details && details.tabId !== -1 && details.tabId === tabId) {
        if (!requestArray.includes(details.url.split('/')[2])) {
          requestArray.push(details.url.split('/')[2])
          apiCheck(
            requestArray,
            tabId,
            mywebsiteCategories,
            resourcesCategories
          )
        }
      }
      getURL().then((host) => {
        if (host && !requestArray.includes(host)) {
          requestArray.push(host)
          apiCheck(
            requestArray,
            tabId,
            mywebsiteCategories,
            resourcesCategories
          )
        }
        setResources(requestArray)
      })
    },
    {
      urls: ['<all_urls>'],
    }
  )
 

I use webRequest API for access resources. For every tab, my function works again. However, when I change the tab I still see another tabs resources. I think before tab still working. Bu I want it finished there and work for my new tab again. How can I do that?

I am adding an image for more understandable.

image

I am telling my actions: First I open nytimes.com tab. Then I switch trklvs.com tab. It doesnt have any resource. However, after some time, I saw nytimes.com resources. (I think it still updating.) How can I fix that?

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!