javascript - Mozilla/JPM: executing a trusted script in an addon HTML page -


i'm learning jpm .

here structure of project:

./lib/utils.js ./index.js ./data/frame.html ./data/icon-64.png ./data/icon-32.png ./data/icon-16.png ./package.json 

i want call trusted function test() defined in lib/utils.js ./data/frame.html

when addon loaded, creates button opens new tab ./data/frame.html.

so far index.js is:

var self = require("sdk/self"); var buttons = require('sdk/ui/button/action');  var tabs = require("sdk/tabs");  var button = buttons.actionbutton({   id: "my-link",   label: "my plugin",   icon: {     "16": "./icon-16.png",     "32": "./icon-32.png",     "64": "./icon-64.png"   },   onclick: handleclick });   function handleclick(state) {    tabs.open({     url: self.data.url("frame.html"),     inbackground: false,     onready:function(tab) {         contentscriptfile: [self.data.url("../lib/utils.js")]         }     }); } 

lib/utils.js starts with:

const utils = require('sdk/window/utils'),       { cc, ci } = require('chrome'),       { read } = require('sdk/io/file')       ; function test() { (...) 

and frame.html :

<html><body> <button onclick=" test()" />test</button> </body></html> 

so far i've tested various things. clicking on buttons displays log "unknown function 'test'". using tag <script src="../lib/utils.js"></ displays error require( undefined. while doc seems say:

to interact trusted content don't need use content scripts: can include script html file in normal way, using <script> tags.

what correct way call function ./data/frame.html

i'm puzzled, can me please?


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -