javascript - Function declared on injected file not recognize from background.js in chrome extension -
i'm trying use https://github.com/povdocs/webvr-starter-kit create chrome pageaction extension.
on manifest.json
file, i've used content_scripts
load jquery.js
, inject.js
.
on inject.js
, i've following codes:
function initvr() { vr.floor(); vr.box({ color: '#ffffff' }).moveto(0, 1.4, 0).setscale(5,4,0); var text = vr.text({ wrap: 4.1, font: '24pt roboto', textalign: 'left', fillstyle : '#000000', text : 'hello world test' }) .moveto(.1, 1.4, 0); }
on background.js
file, i've
chrome.pageaction.onclicked.addlistener(function(tab) { chrome.tabs.executescript(tab.ib, { file: "src/inject/vr.dev.js" }, function(){ initvr(); //calling function declared on inject.js });
the idea here is, when person clicks on pageaction button, injects vr.dev.js
, initialize setup.
when implement this, error saying initvr()
not defined. doing incorrect?
you have use message passing communicate content script,because extension of browser single background script,it have identify tab
Comments
Post a Comment