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

205
Views
How to use chrome.identity.getProfileUserInfo in chrome.webRequest.onBeforeRequest?

How can I use a Chrome extensions API that can be used with a callback function, such as chrome.identity.getProfileUserInfo, in chrome.webRequest.onBeforeRequest?

For example, I have a part of script similar to:

chrome.webRequest.onBeforeRequest.addListener(
  function (request) {
    return { redirectUrl: `https://example.com` };
  },
  // filters here. 
  // permissions here. 
)

The above works, it redirects request attempts to the https://example.com.

But the following, with wrapping the code in a callback function, the return/redirectUrl part is ignored and it doesn't work; it doesn't redirect.

chrome.webRequest.onBeforeRequest.addListener(
  function (request) {

    chrome.identity.getProfileUserInfo(function (profileUserInfo) {
      console.log(profileUserInfo.email);

      return { redirectUrl: `https://example.com` };
    });
  },
  // filters here. 
  // permissions here. 
)

This is a synchronous way that webRequest.onBeforeRequest is only capable of, correct? I use these callbacks, synchronous way because I learnt the chrome extensions API doesn't support an asynchronous way (e.g. async/await, Promise) as I asked on SO other day: javascript - async in chrome.webRequest.onBeforeRequest? - Stack Overflow

So, is it possible, to use chrome.identity.getProfileUserInfo in chrome.webRequest.onBeforeRequest? Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No, you can't. "chrome.identity.getProfileUserInfo" like most "chrome." methods take time to do, therefore the callback function. "chrome.webRequest.onBeforeRequest" only supports the "blocking" option but not "asyncBlocking". But in your case, you could easily assign the ProfileUserInfo to a variable beforehand somewhere in your background script and use it like that.

about 4 years ago · Juan Pablo Isaza Report
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!