'Redirect to packaged HTML file

When using browser.webRequest.onBeforeRequest, I would like to return a redirect to an HTML file packaged in the extension.

I have the extension activated as a temporary extension.

Example of what I'm trying to accomplish:

let pattern = "https://developer.mozilla.org/*";
let targetUrl = "/src/index.html";

function redirect(requestDetails) {
  return {
    redirectUrl: targetUrl
  };
}

browser.webRequest.onBeforeRequest.addListener(
  redirect,
  {urls: [pattern]},
  ["blocking"]
);

If I use an URL like https://example.com, it works. I also tried to use tabs.update("/src/test.html") inside the redirect function, but no luck.

Do I need some permission for this?



Solution 1:[1]

Refer to this comment by wOxxOm for the solution.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1