2

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.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Alec Jacobson
  • 6,032
  • 5
  • 51
  • 88
  • If I change the include to be //@include * then I catch all websites and gmail still steals focus. So is it not using window.focus to do this? How else can it steal focus? – Alec Jacobson Aug 16 '13 at 09:06
  • Use `unsafeWindow.focus = function(){};`, except NinjaKit looks like it might not support `@run-at document-start`. – Brock Adams Aug 16 '13 at 09:33
  • PS: Not sure about Safari, but the `alert()` will cause focus to switch back on some browsers. – Brock Adams Aug 16 '13 at 09:41
  • No go with 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
  • Yeah, you need `@run-at document-start` too. Ninjakit doesn't support it, at a quick glance. – Brock Adams Aug 16 '13 at 14:40
  • Know of an alternative for Safari that does/might? – Alec Jacobson Aug 16 '13 at 15:52
  • No. I'm not a Safari user/expert. It looks like you may be [out of luck with Safari](http://wiki.greasespot.net/Cross-browser_userscripting#Safari). – Brock Adams Aug 16 '13 at 21:38

0 Answers0