After I published the method using Vimperator, I found out it won’t work if user switch to other tab before the page is loaded. The emulated keypress will be only emulated the currently active tab, and that may not be YouTube or Google Groups. Since Google Groups started the new interface, I removed that part of code from my Vimperator configuration, Google Groups doesn’t steal focus anymore. Instead, I even enable Pass Through mode for Google Groups.

A while earlier, I was seeking if there is a way I could open a link from commandline and Firefox does not raise its window. I haven’t found an answer for that but I accidentally stumbled on an answer on Super User and later I found how to disable form focusing on MozillaZine Knowledge Base.

1   Quick Solution

If you are in a hurry, here is what you should do, create a user.js1 in your Firefox profile directory, if it’s not present, with the following content to change Security Policies aka Configurable Security Policies or CAPS for short:


user_pref("capability.policy.policynames", "NoDamnFocusThieves");
user_pref("capability.policy.NoDamnFocusThieves.sites", "http://www.youtube.com http://www.google.com");
// Won't work on Google Search, only domain level is valid
// user_pref("capability.policy.NoDamnFocusThieves.sites", "http://www.google.com/search");
user_pref("capability.policy.NoDamnFocusThieves.HTMLInputElement.focus", "noAccess");

It will disable pages under www.youtube.com and www.google.com to access HTML DOM element’s focus() function.

[1]not editing on prefs.js, it will get overwritten if Firefox is running. If you insist to have setting in prefs.js, you can use about:config page to add those but they will not show up, however, they are really created.

2   About sites

If you need to disable multiple sites, you can create multiple policy names, or you can just put them all into one policy’s sites separated by space. Note that you can NOT specify path, e.g. http://www.google.com/search, it won’t work.

If you disable on Google, it will cause you some trouble. The current Google Search will add the letters, which you type without having search box focused, into search box. But since you disable on the site, the script can’t use focus(), the cursor won’t be in search box and spaces seem to be added instead of what you type. I don’t know why and I am not interested, because I use Vimperator, I can always use hint to select input box.

There is one site this method doesn’t work, Google Dictionary, it still can make the input box get the focus. No idea how it could still set the focus.