I need to get the HTTP response headers send by the server for the main frame in my Tampermonkey userscript. If I am correct there is no way to get the information directly from the userscript.
So, my idea was to write a Firefox webextension to catch the headers, using browser.webRequest.onHeadersReceived.addListener.
function headers_received(obj){
console.log("headers_received["+obj.type+"] : " + obj.url);
console.log(obj.responseHeaders);
}
browser.webRequest.onHeadersReceived.addListener(
headers_received,
{ urls: ['<all_urls>'] },
['blocking', 'responseHeaders']
)
I could inject the data I need in the HTML document from the addon and get it back in my userscript, but I want to avoid modifying the DOM.
The touchy question is : Is there any way to store the data from the Firefox webextension and retrieve it inside the Tampermonkey userscript ?
I tried using this : https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage
function headers_received(obj){
console.log("headers_received["+obj.type+"] : " + obj.url);
console.log(obj.responseHeaders);
let headers = {headers:obj.responseHeaders};
browser.storage.local.set(headers);
}
But I can't retrieve the data from the Tampermonkey userscript.