RedirectUrl not working in Webextension

I’m trying to port Chrome Extension to Firefox.

When this file is to be loaded I’m instead returning “redirectUrl: moz-extension://1bfb861f-d973-4e7c-ab11-dc98b45810e0/resource/visa/js/jquery.js” in the chrome.webRequest.onBeforeSendHeaders.addListener

The actual code is:

return {redirectUrl: chrome.extension.getURL(irctc_urls_redirect[url])};

But it seems this jquery file is not getting loaded and the html page isn’t working properly. What is wrong with this?

If I comment this line then the web page works properly. I’ve already given permission of “webRequest”, “webRequestBlocking”

So, why not do that?
What is it you actually want to achieve?

Intead of loading the javascript file from internet I want to redirect to saved javascript file on the computer so that it saves download time.

Shouldn’t the normal HTTP browser cache already do that job for you? Do you really notice faster loads (in Chrome)?

You could just cancel the request an load jQuery from your local source with a content script

In Chrome Extension I use RedirectUrl to load disk copy of js file.

How to implement what you’re suggesting?

  • where you would usually redirect the request, you cancel it.
  • you attach a content script that attaches a script tag that ether points to the local jQuery (you would need to add the fire to the web_accessible_resources, which is a privacy issue) or includes the jQuery code directly.

You would want the content script to run at document_start, and will have to attach the script to document.documentElement, becaus the head and body won’t exist yet.

But as I said, I can’t imagine that this is worth the trouble (if the server is set up properly for caching).

Oh, and this won’t work if the server send a CSP, which can also be a reason why your current attempt fails.

But what is wrong the way as suggested in this stackoverflow thread?

I’m doing this way which isn’t working. And in Debugger console of background page I’m not seeing any error.

Which way exactly? They are suggesting more than on “in this […] hread”.

@NikasG … is it not the correct way as answered in the stackoverflow?

I didn’t say or imply that, I just wanted to know what exactly you meant.

But as you said youself, it doesn’t work. (Or your problem is something different. I’m not even sure if Firefox allows a redirect to the moz-extension: protocol. By the way, is the jQuery script listed as web_accessible_resource?)

Oh I also see these errors in the background script:

Security Error: Content at https://www.irctc.co.in/eticketing/loginHome.jsf may not load or link to file:///D:/WORKAREA/work/htdocs/netbeans8/webtrial-1/irctc_paid/public_html/resources/irctc/PackedCompressed/packed.js.

It means the redirected localized versions are not allowed to run due to security error. However those have been added in “web_accessible_resources” in manifest.json and already working in Google Chrome

And in manifest.json:

"content_security_policy": "script-src 'self'; object-src 'self'",

already working in Google Chrome

Well, Firefox isn’t Chrome. I doubt Firefox will change its security behaviour to mach Chromes here, which leaves you with three options:

  • the one i described here
  • redirect to a (CDN) server that sets the proper caching headers (so that you should usually have local lookup times for the resource)
  • don’t redirect at all