[WebExtensions] Blocking any downloadable content

RESOLVED WORKSFORME

Status

RESOLVED WORKSFORME
2 years ago
4 months ago

People

(Reporter: antdlmr, Unassigned)

Tracking

53 Branch

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

2 years ago
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36

Steps to reproduce:

Blocking any downloadable content in Google Chrome works:
  chrome.webRequest.onHeadersReceived.addListener( 
    onHeadersReceived,
    { 
      urls:  [ "http://*/*", "https://*/*" ],
      types: [ "main_frame", "sub_frame", "image", "object", "xmlhttprequest", "other" ]
    }, 
    ['blocking','responseHeaders']); 
  function onHeadersReceived( res ) 
  {
      ...................
      var result = [ 
      { name: "Connection-token", value: "close" },
      { name: "Content-Type", value: "multipart/related" }, 
      { name: "Content-Length", value: "0" }];
      return { responseHeaders: result }; <=== BUT IT DOES NOT WORK IN FIREFOX!
    } 
  };					



Actual results:

How can I make the blocking of downloading?
(Reporter)

Comment 1

2 years ago
Error setting response header content-length: [Exception... "Component returned failure code: 0x80070057 
(NS_ERROR_ILLEGAL_VALUE) [nsIHttpChannel.setResponseHeader]"  nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)"  
location: "JS frame :: resource://gre/modules/WebRequest.jsm :: setHeader :: line 214"  data: no]

Updated

2 years ago
Component: Untriaged → WebExtensions: Untriaged
Product: Core → Toolkit

Updated

2 years ago
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1304331
(Reporter)

Comment 3

2 years ago
Sorry, but the reference  bug 1304331 has not led me to the solution of problem.

I need to cancel the request.
I have a solution for Google Chrome, but it does not work for Firefox.
I hoped the Content-Length: 0 for http header rejected the request but any value of this field makes error.
May be there is another solution?

Thank you for help!
(Reporter)

Updated

2 years ago
Status: RESOLVED → UNCONFIRMED
Resolution: DUPLICATE → ---
We don't allow changing the Content-Length header, for a variety of reasons. If you want to cancel the request, please just cancel it.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 years ago2 years ago
Resolution: --- → WORKSFORME
(Reporter)

Comment 5

2 years ago
Yes, my main purpose is to cancel the downloading. How can I do it?
I can not find a way to do it in onHeadersReceived method.
Status: RESOLVED → UNCONFIRMED
Resolution: WORKSFORME → ---
Just return {cancel: true}

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/BlockingResponse#Type
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 years ago2 years ago
Resolution: --- → WORKSFORME

Updated

4 months ago
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.