I'm trying to stop Gmail from stealing focus using a user script. I'm using NinjaKit on safari. So far I have
// ==UserScript==
// @name GMAIL
// @namespace https://mail.google.com
// @include https://mail.google.com/*
// ==/UserScript==
//alert("It's working");
window.focus = function(){};
But still the window manages to steal focus.
I can see that it's indeed activating the userscript if I comment out the alert line: the alert pops up (many times).
Test this by opening mail.google.com/
and then quickly switching to a new tab. Gmail loads in the background but then switches back to focus, stealing it from the other tab.
unsafeWindow.focus = function(){};
either. (The alert was just for a test, it still steals the focus without the alert) (see edited post) – Alec Jacobson Aug 16 '13 at 12:03