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

前端 未结 1 733
终归单人心
终归单人心 2021-01-24 03:01

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

相关标签:
1条回答
  • 2021-01-24 03:44

    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 讨论(0)
提交回复
热议问题