There is an Unfocus add-on that seems to do this well, although right now it's implemented as a command line option. It's in JavaScript of course, but how about using the same underlying mechanism? Looking at the source (save xpi as zip and open components/cmd.js), this appears to be the code that actually does the unfocusing:
function unfocus() {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator);
var browserWindow = wm.getMostRecentWindow("navigator:browser");
There is an Unfocus add-on that seems to do this well, although right now it's implemented as a command line option. It's in JavaScript of course, but how about using the same underlying mechanism? Looking at the source (save xpi as zip and open components/cmd.js), this appears to be the code that actually does the unfocusing:
function unfocus() { classes[ "@mozilla. org/appshell/ window- mediator; 1"]
. getService( Components. interfaces. nsIWindowMediat or); tWindow( "navigator: browser" );
var wm = Components.
var browserWindow = wm.getMostRecen
if( browserWindow. document. commandDispatch er.focusedEleme nt)
browserWindow. document. commandDispatch er.focusedEleme nt.blur( )
browserWind ow.focus( ); ow.focus( );
browserWind
}