Reputation: 30331
In my Firefox addon I'm looking for a secure way to let content code detect the presence of the addon itself. Ideally what I'd like to end up with is allowing content code to query the presence of my addon by executing:
if (window.navigator.my_addon) {
// the addon is present
} else {
// the addon is not present
}
Any suggestion/pointers?
Upvotes: 1
Views: 1561
Reputation: 30331
Adapted from here (but using a getter to make the my_addon value read-only)
// contentWindow is the window object of a contentDocument being displayed
var s = new Components.utils.Sandbox(contentWindow);
s.window = contentWindow;
Components.utils.evalInSandbox("
window.wrappedJSObject.navigator.__defineGetter__('my_addon', function(){
return true; // or whatever we want its value to be
// (note: this is unprivileged code!)
});",
s
);
Upvotes: 2