Chrome Extension: how can I redirect a resource request to a filesystem: url?

1.5k views Asked by At

I have a Chrome extension that basically functions like an advanced "offline mode", where I save all resources requested, and can provide them later when the user requests the url cached resource.

I'm using the webRequest API, and mostly things are working:

  1. The extension is hitting all events I'm registering for
  2. The extension is saving files using the HTML5 filesystem API correctly, and I have found the files stored correctly on my machine.
  3. The extension is able to redirect requests in the onBeforeRequest listener to other http: requests
  4. I am able to access my stored files in Chrome through the filesystem: protocol (like filesystem:chrome-extension://<myExtHere>/persistent/<filename>)

However, I am unable to redirect webRequest requests to urls using the filesystem: protocol. When I try, I get an onErrorOccurred event (error below.)

How can I redirect a chrome webRequest to a filesystem:chrome-extension:// url? or, failing that, How can I redirect a Chrome extension to a local file that the same extension created?

Here is the full error details object, in case it helps.

error: "net::ERR_ABORTED"
frameId: 0
fromCache: false
method: "GET"
parentFrameId: -1
requestId: "22557"
tabId: 6
timeStamp: 1386874360306.4211
type: "main_frame"
url: "http://<redacted, but correct.>"
1

There are 1 answers

2
mildse7en On

This should help some..

return { redirectUrl: chrome.extension.getURL("/your/local/storage.jpg") }