问题
I'm trying to make a printing extension, that can configure printing options and send a print job to the attached printers.
I have made sample extensions other than printing, but the printing API has no methods, just events, so it's not working for me.
Here is my script (Event.js):
chrome.printerProvider.onPrintRequested.addListener(
function( printJob, callback){
var str = printJob.printerId + " , " + printJob.title ;
alert('str: '+ str);
console.log('str: '+str);
appendToLog('str: '+ str );
});
function callback(infos){
console.log('Printing Completed!');
}
As I understood from the documentation, this should be triggered on printing events. But when i print, nothing happens (they are not triggered).
Here is part of my manifest.json:
"background": {
"scripts": ["event.js"],
"persistent": false
},
"permissions": [
"printerProvider"
]
Google PrintProvider JS API: https://developer.chrome.com/extensions/printerProvider
Can anyone tell me what am i doing wrong? or guide me to a useful resources?
回答1:
The printer you're providing has to register itself at onGetPrintersRequested
event first.
Do you understand the purpose of this API? It will not allow you to modify print settings for existing printers. It's kind of a "driver" interface to provide (hence the name) a new printer to Chrome.
来源:https://stackoverflow.com/questions/32459473/google-javascript-api-chrome-printerprovider