Accessing document's javascript variable from firefox extension

后端 未结 3 1824
孤城傲影
孤城傲影 2020-12-10 05:26

is it possible for Firefox extension (toolbar) to access document\'s variables? detailed explanation follows..

loaded document:



        
3条回答
  •  孤城傲影
    2020-12-10 06:08

    If you are working with the new High-Level SDKs then accessing the variable via content scripts is a little different. You can't access the JavaScript objects directly from the add on code, but you can reach them from content scripts that have been attached to an open page via the unsafeWindow object. For example:

    require("sdk/tabs").open({
      url: 'http://www.example.com/some/page/',
      onOpen: function(tab) {
        var worker = tab.attach({
          contentScript: 'unsafeWindow.variableForExtension = 1000;'
        });
      }
    });
    

    To read the variables you'll need to use the port methods on the worker variable as described in Mozilla's content script article.

    Note that there are some security restrictions when dealing with objects and functions. See the articles for details.

提交回复
热议问题