In my scenario, I am using manifest V3 + webrequest with blocking (self hosted extension). Is there a good way to deal with modifying a response header that includes a value that is stored in chrome's storage area? I'm noticing that if I try to retrieve the value inside the callback, that by the time the script resumes (post fetching the value), then the page has already loaded and its too late to modify the header.
I tried using the get function to retrieve a value from the StorageArea. Another approach I tried was using an async funtion with await when fetching the data. Both end up with the same results.
What I did get to work was caching the storage area in a global variable (same as seen in the "Asynchronous preload from storage" section in the storage api documentation (https://developer.chrome.com/docs/extensions/reference/storage/#asynchronous-preload-from-storage). Then I directly used the variable inside the webRequest.onHeadersReceived callback.
Would this be the best approach? Is it reliable? When the service worker eventually is terminated, I'm assuming that the global variable will no longer contain the data that was previously saved and I would have to ensure that it gets re-initialized using other events.