hultqvist
hultqvist

Reputation: 18429

Waiting for an async call in Javascript

I'm using the chrome.experimental.webRequest.onBeforeRequest callback where I need to find the URL of the tab making the request before returning from onBeforeRequest.

This would usually be the referring URL in the HTTP request but I also want the URL where there is no referrer sent such as HTTPS to HTTP requests.

The only thing I found was chrome.tabs.get which is asynchronous.

What would be the best approach to get the tab URL before returning?

I have two ideas on solving this:

  1. Using something similar to ManualResetEvent, though this answer says it is not possible.
  2. Listen to some other event and record each tab URL in a local structure.

Upvotes: 2

Views: 427

Answers (1)

ronme
ronme

Reputation: 1172

I can't think of any good answer to this, except the local structure you offered, and perhaps also using Web Workers, but that seems like an overkill, even if possible.

Upvotes: 1

Related Questions