I'm developing a Chrome extension, and have run into an issue due to developing against a mixture of synchronous and asynchronous apis.
chrome.webRequest.onBeforeSendHeaders.addListener(function(details) {
//code that modifies details.requestHeaders
//..
return {requestHeaders: details.requestHeaders};
},
{urls: ["<all_urls>"]},
["blocking", "requestHeaders"]
Inside the listener function I want to fetch data from IndexedDB and modify the request headers based on this data. IndexedDB only has an asynchronous API, while the contract for the listener requires it to be synchronous.
Any ideas how I could solve this problem?
A DB call is generally too expensive. That said, here is one idea off the top of my head (which might be horrible):
That being said, you would need to think of the user experience in the event of a cache miss. Maybe supply a default parameter, or a placeholder value of some sort that notifies the user of the miss somehow. It kind of depends on how you want the app to work and what the app does, which you did not state.
Oh, derp, and consider using localStorage as the in memory map... Duh.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.