开发者

Allow content documents (web pages) to detect my Firefox addon

开发者 https://www.devze.com 2023-02-13 02:20 出处:网络
In my Firefox addon I\'m looking for a secure way to let content code detect the presence of the addon itself.

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?


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
);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号