WebExtensions: webRequest.blockResponse with body response?

Hi.

I block the request of certain URLs and I want to respond with a custom HTML page. What’s the recommended way to do so?

browser.webRequest.onBeforeRequest.addListener(
  function(details){

// return HTML as well

 return { cancel: true};
},
  { urls: ["http://www.example.com/"] },
  ["blocking"]
);

You can try “Redirecting requests”

Any other way? Without changing document.location?

That will look like Phishing and not allowed.

I have a third party javascript library which only operates when the window.location property is set correctly. I want to seperate it from the page. At the moment I do cancel the request but modify the response. It would be nicer to cancel the request before it is done than modifying just the response.

Try the StreamFilter API, supported from Firefox 57.