Closed Bug 1389003 Opened 7 years ago Closed 7 years ago

Please provide an option for new tab overrides to set focus to website instead of location bar

Categories

(WebExtensions :: General, enhancement)

enhancement
Not set
normal

Tracking

(firefox57 affected)

RESOLVED DUPLICATE of bug 1295400
Tracking Status
firefox57 --- affected

People

(Reporter: soeren.hentzschel, Unassigned)

References

Details

I am in the progress of porting my add-on New Tab Override [1] to a WebExtension [2]. One important feature of New Tab Override is to set the focus to the website instead of the location bar. Please provide a way for WebExtensions to do the same.

[1] https://addons.mozilla.org/en-US/firefox/addon/new-tab-override/
[2] https://github.com/cadeyrn/newtaboverride/commits/web-ext

USE CASE:

There are several add-ons overriding the new tab page of Firefox. Per default the location bar has the focus so that users can immediately start typing. Well, that's not yet the case with WebExtensions, users have to clear the location bar manually… But the point is: the location bar has the focus and this makes a lot of sense in many cases.

But: a lot of users of such add-ons use a search engine as new tab page and these users want to set the focus to the search field of the search engine so that they can immediately start typing in the search field.

WHAT I NEED:

So I don't suggest to change the default behaviour. It's really important to have a option to either use the one or the other behaviour because both make sense and it fully depends of the new tab page which behaviour is expected.

PROPOSAL:

My preferred way would be an option for the tabs.update() API. Something like:

browser.tabs.update({ url : "https://www.google.com", focusWebsite : true });

If you have another suggestion that's okay, I am okay with every solution. But PLEASE provide a solution for this use case. Before I had this feature implemented in my SDK version of New Tab Override I got almost daily requests to implement this feature so this is really a must-have feature for my add-on.
For reference: this was my solution in the SDK based add-on:

const { viewFor } = require('sdk/view/core');
const tabs = require('sdk/tabs');
const tabutils = require('sdk/tabs/utils');

…

const focus_website = simplePrefs.prefs['focus_website'];
    if (focus_website) {
      tabs.on('open', newtaboverride.focusListener);
    } else {
      tabs.removeListener('open', newtaboverride.focusListener);
}

…

focusListener: function (tab) {
    let tab_opened = true;
    tab.on('ready', function () {
      if (tab_opened) {
        let xultab = viewFor(tab);
        let browser = tabutils.getBrowserForTab(xultab);
        browser.focus();
        tab_opened = false;
      }
    });
}

Not very beautiful, but it worked.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → DUPLICATE
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.