简体   繁体   中英

How can I capture traffic originating from my own Firefox Web Extension

I am working on a Firefox Extension ( WebExtension ) which, as one of it's functions, needs to request resources from the network and override response headers, especially those that control how the browser treats the response (for example, gzip encoding should be removed from content-encoding to retrieve the 'raw' response).

The problem is that I cannot find a way to intercept requests, made by my extension. This works fine in Chrome, and I can intercept requests, made by the user directly.

This problem affects all webRequest handlers, but the example is for onHeadersReceived (simplified to the bare minimum):

function OnHeadersReceived(details){
    console.log('Received headers for ' + details.url);
}

chrome.webRequest.onHeadersReceived.addListener(OnHeadersReceived, { urls: ['<all_urls>'] });

And here is a very simple example of the request:

fetch('http://www.alexa.com')

Same problem applies to XMLHttpRequest .

Any insight into this problem is appreciated. I know that Chrome does not allow to intercept requests, originated in other extensions, but has nothing against requests originated within your own extension.

UPDATE

Found a bug on BugZilla: WebExtensions: webRequest listeners do not fire for XMLHttpRequest requests generated by the extension

如果其他人想知道,这是Firefox中的一个问题,它在版本52中得到修复。现在,来自Web扩展的所有请求也被这些扩展中的处理程序拦截。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM