Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listener to change url before loading it on Mozilla SDK

I'm trying to get something similar to a typo correction for the location bar on mozilla sdk. The user inputs a url on the locationbar and it gets changed before it is loaded. I've tried:

sdk/pagemod as seen here. The problem is it runs when the page starts rendering, not before it starts downloading it.

sdk/tabs => It doesn't have a event that gets called before it starts loading a website.

Above is what I've found that would catch websites the user is trying to enter into. I have also found sdk/system/events, but the only event I found I could use is http-on-modify-request, this does catch every http request. The problem is, you can't modify the url of that request.

To solve this I've seen 2 options:

This addon's way => Get the current tab and load there the new url. The problem is clear, the request may not be from a url the user is trying to load, but from a url inside a page's html. I tried comparing the request url to tabs.activeTab.url, but it gets set after the http-on-modify-request event is sent.

or the solution explained here that I am not sure could work (it is not for mozilla sdk).

So basically my problem right now could be solved with:

-a way to capture the url from the location bar before it starts loading & changing it (I haven't seen anything for this on the sdk) or -a way to know when a request corresponds to a website the user is trying to load in the location bar or -a way to modify the request (url)

like image 630
dyeray Avatar asked Mar 30 '14 00:03

dyeray


People also ask

What are reserved URLs in Firebase?

These reserved URLs are available both when you deploy to Firebase ( firebase deploy) or when you run your app on a local server ( firebase serve ). Because Firebase Hosting is served over HTTP/2 when deployed, you can boost performance by loading files from the same origin.

How do I get around the https restriction in Firefox?

When testing you can get around the HTTPS restriction by checking the "Enable Service Workers over HTTP (when toolbox is open)" option in the Firefox Developer Tools settings. The "Forget" button, available in Firefox's customization options, can be used to clear service workers and their caches ( bug 1252998 ).

How do I configure the firebase JavaScript SDK?

This Firebase configuration and SDK initialization is provided by a script that you can include directly: <!-- Load the Firebase SDKs before loading this file --> When you deploy to Firebase or test your app locally, this script automatically configures the Firebase JavaScript SDK for the active Firebase project and initializes the SDK.

How to enable service workers over HTTPS in Firefox?

You can navigate to about:debugging to see what SWs are registered and update/remove them. When testing you can get around the HTTPS restriction by checking the "Enable Service Workers over HTTP (when toolbox is open)" option in the Firefox Developer Tools settings.


2 Answers

I do that in my add-on Google Redirects Fixer which source code you can see here.

Basically, what you're looking for is listening to the http-on-modify-request event. If you follow that code you'll see how to intercept the request and, under certain conditions, abort it and replace it with a new request.

Hope it helps.

like image 171
matagus Avatar answered Oct 27 '22 18:10

matagus


"sdk/pagemod as seen here. The problem is it runs when the page starts rendering, not before it starts downloading it."

You can tell it to attach before any content is loaded with contentScriptWhen: start.

Load content scripts immediately after the document element is inserted into the DOM, but before the DOM content itself has been loaded

like image 37
willlma Avatar answered Oct 27 '22 17:10

willlma