window.focus stopped working

4,472 views
Skip to first unread message

Robert Inder

unread,
Feb 7, 2018, 10:06:31 AM2/7/18
to Chromium-discuss
Chrome v64 has actually disabled window.focus().

(( I originally posted this to the Chrome Help Forum, but the only reply there has
    been to suggest I should (re-)post here...))

We have code that coordinates multiple tabs/windows.  

In some situations, a subordinate window wants to pass
the user back to the main window (i.e. its opener).
It does this by invoking code in the main window which
uses window.focus() to bring itself to the top -- 
i.e. to transfer focus from the child window/tab to the main one.
The main window also puts up an alert, to tell the user what has changed.

Now I have upgraded to Chrome 64, this no longer works.
I can see (log messages, breakpoint) the call to focus() happening in the
(buried) master window. But it is no longer being exposed: the
subordinate tab/window remains "on top".

This is a pain.

Is this a bug?  Or a "feature"? 
If the latter, how do I get the functionality I need?

Robert.




PhistucK

unread,
Feb 7, 2018, 10:09:48 AM2/7/18
to rober...@gmail.com, Avi Drissman, Chromium-discuss
window.focus() does not work for a long time, as far as I know.
What might have changed in Chrome 64 is that alert() no longer works if Chrome determines that it is harassing the user (for example, alert() in an unfocused window/tab), or if the user does not engage a lot with that website.

Avi, any thoughts?


PhistucK

--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

Avi Drissman

unread,
Feb 7, 2018, 12:55:47 PM2/7/18
to PhistucK, rober...@gmail.com, Chromium-discuss
I think you are conflating two things.

On Wed, Feb 7, 2018 at 4:15 PM, Robert Inder <rober...@gmail.com> wrote:
In some situations, a subordinate window wants to pass
the user back to the main window (i.e. its opener).
It does this by invoking code in the main window which
uses window.focus() to bring itself to the top -- 
i.e. to transfer focus from the child window/tab to the main one.
The main window also puts up an alert, to tell the user what has changed.

You said that two things happen. The main window 1) calls window.focus() and 2) calls window.alert().

Windows cannot focus themselves via window.focus(). They haven't been able to do that since 2012 (1, 2). What was really happening for you in pre-Chrome 64 is that the call to window.focus() was entirely ignored, and that the window.alert() call was the one that brought the window to the front.


The ability for pages to activate themselves is wildly abused on the web, and thus is being removed from Chrome wherever possible. I don't have any suggestions for you. I'm sorry.

Avi

Avi Drissman

unread,
Mar 20, 2018, 2:09:40 PM3/20/18
to david....@gmail.com, Chromium-discuss, PhistucK Productions, Robert Inder
You can no longer use alert for that. If this situation doesn't fall into the category allowed by window.focus, then I'm not sure there is a way to do that.

Avi


On Tue, Mar 20, 2018 at 2:05 PM David Flammer <david....@gmail.com> wrote:
Avi,

Here is another use-case, which has apparently been disabled by this change. Emails often link to a site with pertinent information to open something in a site.

Since this opens a new tab, to avoid tab proliferation, we use a broadcast to look for an existing tab that can take the request, and if one is found, we alert to that tab, and close the tab that was opened.

With this change, is there a way to focus to another tab from the currently active tab? I think the use-case described by the original poster, and this case, don't really fall under the abuse you're trying to avoid, since it is instigated by the currently active tab. 

Thanks,
David

PhistucK

unread,
Mar 20, 2018, 5:26:12 PM3/20/18
to David Flammer, Chromium-discuss, Robert Inder, Avi Drissman
crbug.com is also for feature requests. I would not count on it being implemented. While it is valid, it is probably extremely uncommon.


PhistucK

On Tue, Mar 20, 2018 at 8:29 PM, David Flammer <david....@gmail.com> wrote:
I respect Chrome disabling features that are widely abused, but it would be nice if some thought were put toward creating safe workarounds for valid use-cases before disabling the functionality. 

As far as I can tell, there is currently no way to pass focus from one tab to another, even though the use-cases described are valid. If there is another way, I'l love to hear about it.

If not, is there a formal way to request features? Perhaps one could augment BroadcastChannel to pass focus from one tab to another? Since both tabs would have to be in some form of agreement, it would seem like a safe work around.

David Flammer

unread,
Mar 21, 2018, 1:29:59 AM3/21/18
to Chromium-discuss, phis...@gmail.com, rober...@gmail.com, a...@chromium.org

David Flammer

unread,
Mar 21, 2018, 1:29:59 AM3/21/18
to Chromium-discuss, david....@gmail.com, phis...@gmail.com, rober...@gmail.com, a...@chromium.org
I respect Chrome disabling features that are widely abused, but it would be nice if some thought were put toward creating safe workarounds for valid use-cases before disabling the functionality. 

As far as I can tell, there is currently no way to pass focus from one tab to another, even though the use-cases described are valid. If there is another way, I'l love to hear about it.

If not, is there a formal way to request features? Perhaps one could augment BroadcastChannel to pass focus from one tab to another? Since both tabs would have to be in some form of agreement, it would seem like a safe work around.

On Tuesday, March 20, 2018 at 12:09:40 PM UTC-6, Avi Drissman wrote:

PhistucK

unread,
Mar 31, 2018, 5:44:21 PM3/31/18
to Алексей Несвятипасха, Chromium-discuss, David Flammer, Robert Inder, Avi Drissman
You can use desktop notifications (new Notification(...)) for that.


PhistucK

On Sun, Apr 1, 2018 at 12:03 AM, Алексей Несвятипасха <alex...@gmail.com> wrote:
Hi, I have the same question about window.focus(). Is it possible to add permission use focus for necessary sites? I work with the site (corporate source) in many tabs and sometimes it really needs to know about changes in other tabs (your session is closed.. someone fixed the issue and so on)

среда, 21 марта 2018 г., 7:29:59 UTC+2 пользователь David Flammer написал:

Алексей Несвятипасха

unread,
Apr 1, 2018, 5:11:07 AM4/1/18
to Chromium-discuss, david....@gmail.com, phis...@gmail.com, rober...@gmail.com, a...@chromium.org
Hi, I have the same question about window.focus(). Is it possible to add permission use focus for necessary sites? I work with the site (corporate source) in many tabs and sometimes it really needs to know about changes in other tabs (your session is closed.. someone fixed the issue and so on)

среда, 21 марта 2018 г., 7:29:59 UTC+2 пользователь David Flammer написал:
I respect Chrome disabling features that are widely abused, but it would be nice if some thought were put toward creating safe workarounds for valid use-cases before disabling the functionality. 
Reply all
Reply to author
Forward
0 new messages