1

I'm making add-on modules for several browsers, including Chrome and Firefox.

I just did what I want with Chrome : overriding new tab url to load a HTML file with the manifest.json. Pretty simple. (Now I'm able to copy paste again :)) :

  ...

  "chrome_url_overrides" : {
    "newtab": "override.html"
  },

  ...

When the user create a new blank tab, it overrides the default page and loads the file I want : override.html, with the same behavior (no URL in the address bar).

But now, I want to do the same thing with Firefox using Add-on SDK. I tried using browser.newtab.url :

var { get, set } = require("sdk/preferences/service");
var { when: unload } = require("sdk/system/unload");

var oldValue = get("browser.newtab.url");

set("browser.newtab.url", 'http://www.example.com');

// Restore old setting when unload
unload(function() {
  set("browser.urlbar.autoFill", oldValue);
});

It works, but I really would be able to load an HTML file instead giving it a new URL (the code would be more maintainable) and keep a clean address bar.

Any ideas ?

enguerranws
  • 8,087
  • 8
  • 49
  • 97
  • http://stackoverflow.com/questions/25327282/why-is-this-javascript-page-redirect-so-slow/25328750#comment50107606_25328750 – Noitidart Jul 07 '15 at 15:31
  • Thank you, but I don't see the link with what I'm asking : I can replace URL on new tab, but I want to load a file (just as “chrome_url_overrides” does). Sorry if it wasn't clear. – enguerranws Jul 08 '15 at 07:47
  • simply replace the URL redirection with path to your file and it will work. :) You will have to use file uri probably. If that doesnt work then try resource/chrome uri and it will. – Noitidart Jul 08 '15 at 15:07
  • But the user will see the file URI in the address bar ? – enguerranws Jul 08 '15 at 15:25
  • Yes but if you don't want them to you can mask it. You can create a custom protocol so it would forward to `my-protocol:page1` or you can make an about page so `about:my-addon-page1`. Here is how to do about url: https://developer.mozilla.org/en-US/docs/Custom_about:_URLs and here is how to do a custom protocol: http://stackoverflow.com/questions/24917460/nsiprotocol-example-unclear or dont bother with protocols and simply override the url displayed without changing path with: http://stackoverflow.com/a/23679249/1828637 – Noitidart Jul 09 '15 at 02:41
  • On deeper though, taking the original code from my firs tlink, and instead of redirecting it with `redirectTo` you can abort the page load and then redirect the webNavigation object which will not change the url, this is actually an interesting though, i'll give this a shot and share the results. The idea for this is based on when you navigate to a bad page, it shows you the "problem loading page" right, well that was a webNav redir. Same with if youre offline and nav to any page, it redirs webNav to "u are offline" but doesnt change url. – Noitidart Jul 09 '15 at 02:44
  • 1
    Thanks for this, I'm gonna try it. – enguerranws Jul 09 '15 at 07:11
  • Actually I can't make this work... Have you have an idea how I could achieve that with my existing code ? – enguerranws Jul 22 '15 at 09:07
  • Yes share with me what you have so far, put it up on github and link me :) – Noitidart Jul 22 '15 at 09:13
  • Basically, it's in my question, what I tried since that is not working... – enguerranws Jul 22 '15 at 09:14
  • Whats in your post doesnt help me, im not an sdk guy. If you want to work in sdk, i dont have the environment but If you get on irc i can hold your hand through it, i would have to connect to your computer, or you to mine. – Noitidart Jul 22 '15 at 09:17

0 Answers0