New Tab URL

Hello,

I’d like to wish AMO team a Happy New Year! May you continue your excellent & unique work.

About this great add-on: https://addons.mozilla.org/en-US/firefox/addon/new-tab-override/

If I develop a WebExtensions add-on, and wish to offer my users (opt-in mechanism, default FALSE) to change the new tab URL to a certain URL (ex. my blog) as a means of supporting my add-on:

  1. Can I do it?

  2. If the answer is Yes, can you refer me to the relevant API.?

Thank you for your gracious help,
Larry P.

1 Like

Happy new year Larry! The WebExt api doesn’t allow for this.

There is no “New Tab API” in the WebExtension world, but it’s possible. I implemented a way in my WebExtension prototype of New Tab Override. It’s not great, but it works (more or less).

simplified example:

const newtabdemo = {
  getActiveTab : function () {
    return browser.tabs.query({ active : true, currentWindow : true });
  },

  openNewTabPage : function () {
    newtabdemo.getActiveTab().then((tab) => {
      browser.tabs.update(tab.id, { url : 'https://www.google.com' })
    });
  }
};

browser.tabs.onCreated.addListener(newtabdemo.openNewTabPage);

In my prototype the settings UI (including i18n) is already implemented but I think implementing the settings UI was not part of the question, so I simplified the example.

edit: you have to consider edge cases like opening preferences, homepage and so on (so please don’t use my example without the needed changes :wink: ), that’s why it’s not great. But I don’t think that that’s not doable.

I hope there will be a proper API in time for Firefox 57…

1 Like

Thank you for your quick reply.

I just need a solution, where when the user opts-in, and as long as my add-on stays on his browser, the URL appearing when opening a new tab is the URL I define (like: xxxx.blogspot.com) - exactly as this add-on performs: https://addons.mozilla.org/en-US/firefox/addon/new-tab-override/.

  1. Does the code you posted (under “simplified example:”) support it?
  2. How can I reverse this operation, so the user returns to get the “ordinary” new tab landing page?

I wish you a Happy New Year!

Larry P.

The example code “replaces the new tab page”, but it also opens the defined url when it really shouldn’t, for example when opening the settings. So my example is an approach, not a complete solution.

I won’t invest more time to complete this approach, I am waiting for a new API. If there won’t be an API then I still can spend time to make it right. My SDK based add-on still works till November 2017 (release of Firefox 57) so I have a bit time.

My example does not include the opt-in part.

1 Like

https://bugzilla.mozilla.org/show_bug.cgi?id=1234150

You can allow the user to override the new tab page in an extension by simply setting the new tab page to a chrome URL in your extension and then having that chrome URL navigate to the correct page. (That’s how you do it in the Chrome browser).

It’s not yet implemented but it’s planned to implement.