Focus page instead of address bar on new tab

(Ru Kom) #1

I have overrided new tab in my extension and want to listen to keystroke events. But when new tab is open, focus is always on address bar and event listeners hears nothing. Due to this user has to click anywhere on page before keystroke handlers be able to recognize anything. Not so comfortable.

Is there ways to set focus to page automatically? window.focus() and document.body.focus() in load handler didn’t work.

(Martin Giger) #2

It appears one way of achieving this is to simply immediately close the newtab page and re-open the custom landing page:

(Ru Kom) #3

I need to think about it for my own situation. But actually I want to make option to focus page or address bar. Your answer can be useful but what about contrary - to set focus to address bar?

(Martin Giger) #4

Just don’t do anything and let the focus rest in the address bar?

(Ru Kom) #5

If new tab is opened with browser.tabs.create(), focus is on the page, so it goes. In my ext both scenarios are possible.

(Juraj Masiar) #6

Also be aware that in Firefox 61 (release date tomorrow) if you set new tab page as homepage then opening new window will focus the page, not the addressbar.

I agree there should be a way for extensions to control focus even if it would require new permission - I’m not sure if there is a bug for that already…

(Ru Kom) #7

Thanks, I’ll keep it on mind. Is there anywhere info about dev API updates? I would like to know when some experimental features be released.

(Juraj Masiar) #8

Yes there is:

Specifically the articles that starts with “Extensions in XX”, for example:

They are being released shortly after new Beta version is released so there should be new article about new features in upcoming Beta 62 soon.

New article for 62: