Reputation: 10958
In a Firefox add-on built with the Add-on SDK, how can I disable and re-enable JavaScript for a single tab?
Upvotes: 5
Views: 3191
Reputation: 57671
The SDK itself doesn't provide this functionality, you will have to work with the XUL directly. What you need to do is accessing the docShell
property of the XUL <browser>
element corresponding to the tab. The docshell has an allowJavascript
property that lets you switch JavaScript on and off. Something like this should work:
var window = require("window-utils").activeBrowserWindow;
var tabBrowser = window.gBrowser;
var browser = tabBrowser.selectedBrowser; // or: tabBrowser.browsers[n]
browser.docShell.allowJavascript = false;
Unfortunately, it doesn't seem possible to take a Tab
object and find the corresponding XUL element - you have to work with the XUL window from the start.
Relevant documentation:
window-utils
package (the properties activeWindow
/activeBrowserWindow
are undocumented for some reason).<tabbrowser>
element<browser>
elementnsIDocShell
interfaceUpvotes: 5