After I published the method using Vimperator, I found out it wont 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 doesnt 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 havent 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 its 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", "");
// Won't work on Google Search, only domain level is valid
// user_pref("capability.policy.NoDamnFocusThieves.sites", "");
user_pref("capability.policy.NoDamnFocusThieves.HTMLInputElement.focus", "noAccess");

It will disable pages under and to access HTML DOM elements 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 policys sites separated by space. Note that you can NOT specify path, e.g., it wont 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 cant use focus(), the cursor wont be in search box and spaces seem to be added instead of what you type. I dont 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 doesnt work, Google Dictionary, it still can make the input box get the focus. No idea how it could still set the focus.