ChrisNZL / Fauxbar

An alternative to Chrome's Omnibox.
https://chrome.google.com/webstore/detail/fauxbar/hibkhcnpkakjniplpfblaoikiggkopka
MIT License
90 stars 13 forks source link

Update "Steal focus from Omnibox" behaviour with better solution #70

Open ChrisNZL opened 2 years ago

ChrisNZL commented 2 years ago

Fauxbar 1.8.1 has an option: Options > General > Override Chrome's New Tab button

If enabled (default), Fauxbar closes the New Tab Page, then opens another page, all in an effort to steal focus from Chrome's Omnibox.

Back in 2013, Chrome 27 changed its behaviour, resulting in the inability for New Tab Page extensions to steal focus from the Omnibox.

My workaround to steal focus was to close the New Tab Page, then open a regular tab, allowing Fauxbar to take focus.


A better solution has arised: by changing location.search, extensions can utilise autofocus or call .focus() to steal focus.

So rather than closing the New Tab Page and opening a regular tab, as a small test, the following code seems to steal focus from Chrome's Omnibox successfully, while only adding a small ? to the visible URL:

let q = "?";
if (location.search !== q && !location.href.includes(q)) {
    location.search = q;
}

Will be worth keeping the old code to close the New Tab Page in case this workaround ever breaks.

But, keen to implement this; not needing to close the New Tab Page will be an improvement.