-
Notifications
You must be signed in to change notification settings - Fork 233
Description
On Chrome, chrome.devtools.network.onRequestFinished.addListener emits a chrome.devtools.network.Request object, which includes a getContent() method that invokes a callback with string content and its encoding. Correct usage looks like:
chrome.devtools.network.onRequestFinished.addListener((req) => {
req.getContent((content, encoding) => {
// ...
});
});With Web Extensions, getContent() should return a Promise rather than being callback based. For example:
browser.devtools.network.onRequestFinished.addListener(async (req) => {
const [content, encoding] = await req.getContent();
});Currently however, the Web Extensions polyfill simply passes through what it receives from Chrome, so getContent() is still callback based.
I wasn't able to find browser.devtools in the spec, however MDN does say that this method exists and does in fact return a Promise. firefox-webext-browser also says this returns Promise<object>. I'm not totally clear if this is an official part of the spec, or a Firefox-specific API.
My questions here are:
- Is
browser.devtools.network.onRequestFinishedactually defined in the Web Extensions spec somewhere? - What exactly is the return type?
Promise<object>is pretty vague and MDN doesn't provide specifics.- Chrome returns a tuple of
[string, string], where the former is the content as a string or a base64 encoded string (if binary), and the latter is an empty string or'base64'(if binary). I'm not sure what the expected behavior of Web Extensions would be for binary data?
- Chrome returns a tuple of
I'm happy to write up a PR to implement this if it is appropriate to add to this polyfill. I'm not totally clear on where this API stands with respect to the spec, but if you're willing to merge it, I'm happy to write it.