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

234
Views
How to execute executeScript before completing onBeforeRequest?

I have a function that intercepts the request and changes the url based on the data from the page

function my_func(requestDetails) {
  var count="0";
  chrome.tabs.executeScript(null, { //Add jquery
        file: "jquery-3.6.0.min.js",
  });
  
  chrome.tabs.executeScript(null, { //Get count
            file: "test.js",
    }, function (result) {
        count=result;     
        console.log("Result "+result);  
  });

  console.log("After "+count);
  return {
    redirectUrl : "https://another.site/ext.php?count="+count
  };  
}

Intercepts the request and calls my_func

chrome.webRequest.onBeforeRequest.addListener(
  my_func,
  {
    urls: ['https://www.site.ru/command'] // or <all_urls>
  }, ["blocking"]
);

test.js Takes text from select and returns it

test=$('select[ng-model="operation.test"] option:selected').text();
test;

When queried in the console, I get this

After 0
Result 1

chrome.tabs.executeScript terminates after executing my_func's return, and I need to do the opposite somehow. What can I do?

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!