Skip to content

browser.devtools.network.onRequestFinished does not promisify getContent() #249

@dgp1130

Description

@dgp1130

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:

  1. Is browser.devtools.network.onRequestFinished actually defined in the Web Extensions spec somewhere?
  2. 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?

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions