我正在尝试创建一个chrome扩展程序,以将打开的抽屉命令发送给epson智能打印机。 SDK会生成一个在基本HTML页面上运行时可正常工作的代码段。在我的chrome扩展程序生成的HTML中用作背景脚本时,相同的代码不起作用。“ epson Libary”已成功调用,但是。 我想念什么?
{
"manifest_version": 2,
"name": "Pop the Draw",
"description": "This extension will ????",
"version": "1.0",
"permissions": ["background","activeTab"
],
"browser_action": {
"default_icon": "icon.png"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["test.js"]
}
],
"background": {
"scripts": ["test.js","epos-2.9.0.js"],
"persistent": true
}
}
function popdrawer() {
var printer = null;
var ePosDev = new epson.ePOSDevice();
ePosDev.connect('192.168.1.21', 8008, cbConnect);
function cbConnect(data) {
if(data == 'OK') {
ePosDev.createDevice('local_printer', ePosDev.DEVICE_TYPE_PRINTER, {'crypto' : true, 'buffer' : false}, cbCreateDevice_printer);
} else {
alert(data);
}
}
function cbCreateDevice_printer(devobj, retcode) {
if( retcode == 'OK' ) {
printer = devobj;
executeAddedCode();
} else {
alert(retcode);
}
}
function executeAddedCode() {
printer.addPulse(printer.DRAWER_1, printer.PULSE_100);
printer.send();
}
}
console.log ("fire Now")
chrome.tabs.executeScript(null, {file:"epos-2.9.0.js"})
chrome.browserAction.onClicked.addListener(popdrawer)