I figured out from Bugzilla that you can set your options url in install.rdf to arbitrary js and it will run perfectly fine. The only issue is that the window deactivates, its as if an invisible dialog has opened over it, and no matter what you can’t close it.
For example:
In my addon here: simple test case, on startup it just alerts startup, and in addon manager it will show options button, on click it will do a notifyObserver
but then it goes all dialog mode:
GitHub :: Noitidart / PortableTester
You can install this addon straight from repo with GitHubExtensionInstaller addon
Code in my optionsurl:
<em:optionsURL> javascript:Components.utils.import('resource://gre/modules/Services.jsm');Services.obs.notifyObservers(window, 'hellothisisyourcaptainspeaking', 'options') </em:optionsURL>
I would like to revent going into this invisible dialog mode after click of options button. Or if we can’t prevent it, I’d want to add some code to the optionsurl to exit this locked up mode.
On this note I have tried this code and it didn’t work:
javascript: Components.utils.import('resource://gre/modules/Services.jsm'); Services.obs.notifyObservers(window, 'hellothisisyourcaptainspeaking', 'options'); var DOMWin = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebNavigation).QueryInterface(Components.interfaces.nsIDocShellTreeItem).rootTreeItem.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow); var utils = DOMWin.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils); utils.leaveModalState();
This can be seen in this commit here: GitHub :: Noitdart / PortableTester commit showing trying to leave this dialog mode
Advertisement
Answer
You cannot prevent the Add-ons Manager from opening a modal dialog. You can however easily close it, just add window.close()
to your command. That assumes that your code is running in the context of that modal dialog – if not then Services.wm.getMostRecentWindow(null).close()
should do.
However, I consider using a javascript:
URL here awkward, this approach might also break in future. You should consider using a minimal XUL dialog (without any stylesheets, so it will be invisible as well) that includes a JavaScript file. Then you will have your code in a proper script file rather than squeezing it all into one line in install.rdf
.