The default bug view has changed. See this FAQ.

WebRequest API does not support file: requests

UNCONFIRMED
Unassigned

Status

()

Toolkit
WebExtensions: Request Handling
P3
normal
UNCONFIRMED
a month ago
23 days ago

People

(Reporter: testit, Unassigned, NeedInfo)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: triaged)

Attachments

(1 attachment)

1011 bytes, application/x-zip-compressed
Details
(Reporter)

Description

a month ago
Created attachment 8839529 [details]
testit.zip

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0
Build ID: 20170125094131

Steps to reproduce:

My extensions registers as a listener to webRequest.onBeforeRequest. This is done to redirect the user to my extension main page if he opens a local epub file.

Here are the steps to reproduce the problem:

- Download and unzip the attached test case. Load the extension via "about:debugging". 

- Open the file explorer and open the file "testit.epub" (included in the zip file) via right click and by selecting "Firefox".

- The standard file save dialog is displayed.

As my extension registered as a listener to webRequest.onBeforeRequest with a filter to all file URLs with the extension ".epub", the request should be redirected to the main page of my extension. The file url should be passed as a parameter.

The reason this didn't happen is, that access to file URLs was not granted to my extension. Currently exists no user interface to grant access to file URLs.

So in general this is not a bug because the extension behaves as expected. I created this bug to show a use case for granting access to file URLs.

Updated

a month ago
Status: UNCONFIRMED → RESOLVED
Last Resolved: a month ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1256122
(Reporter)

Comment 2

a month ago
This is not a duplicate of bug 1256122. 

The redirect in 1256122 fails because it's not allowed to redirect a http:// url to an extension page. An error message is logged.

The redirect in this bug fails, because no access to file URLs is granted. The webRequest.onBeforeRequest listener is not called at all. No error message is logged.
Status: RESOLVED → UNCONFIRMED
Resolution: DUPLICATE → ---

Updated

a month ago
Summary: Redirect to extension page fails if no access to file URLs is granted → WebRequest API does not support file: requests

Comment 3

a month ago
I think the problem come from the `browser.webRequest.onBeforeRequest.addListener`'s filter `"urls": ["file://*/*.epub", "file://*/*.EPUB"]`.
The syntax is invalid according to https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Match_patterns#Invalid_match_patterns
Should be `"urls": ["file:///*.epub", "file:///*.EPUB"]`
(Reporter)

Comment 4

a month ago
(In reply to Memmie Lenglet from comment #3)
> I think the problem come from the
> `browser.webRequest.onBeforeRequest.addListener`'s filter `"urls":
> ["file://*/*.epub", "file://*/*.EPUB"]`.
> The syntax is invalid according to
> https://developer.mozilla.org/en-US/Add-ons/WebExtensions/
> Match_patterns#Invalid_match_patterns
> Should be `"urls": ["file:///*.epub", "file:///*.EPUB"]`

I tried it with the changes you suggested. Unfortunately, this doesn't make a difference, it still doesn't work.

Comment 5

a month ago
Ok I found the why. In fact the docs says:
"Only requests made using HTTP or HTTPS will trigger events, even though match patterns can match some other protocols"
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/RequestFilter

An API like registerContentHandler should be used, but it's seem impossible to use with WebExtensions:
"For security reasons, it's not possible for an extension or web site to register content handlers targeting other sites"
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerContentHandler

Updated

a month ago
Blocks: 1341098

Comment 6

a month ago
file system investigate
Flags: needinfo?(amckay)

Updated

23 days ago
Priority: -- → P3
Whiteboard: triaged
You need to log in before you can comment on or make changes to this bug.