So, I got Firefox 56 (Ubuntu Gnome) yesterday and I started experimenting with tabs.saveAsPDF() function (Firefox 56+). So on the site the example that they have shown is for a background script. But I want to trigger it only when I press a button. So I made a button, and wrote this code in the .js
file (a popup).
var savepdf = document.querySelector('.savePDF');
savepdf.addEventListener('click', saveaspdf);
function saveaspdf(){
console.log('Inside saveaspdf'); //for checking
browser.tabs.saveAsPDF({footerCenter:"hello",footerLeft:"2",footerRight:"4/10/2017",headerCenter:"Mera Baba",headerLeft:"Baba",headerRight:"Baba",marginBottom:0.5,marginLeft:0.5,marginRight:0.5,marginTop:0.5,orientation:0,paperHeight:11.0,paperSizeUnit:0,paperWidth:8.5,scaling:1,showBackgroundColors:false,showBackgroundImages:false,shrinkToFit:true})
.then((status) => {
console.log(status);
});
}
When I click the button, the window for saving it as pdf comes(say I select Desktop), and I hit save. Nothing happens(the downloads addon also doesn't turn blue) and a corrupted pdf file is saved to my desktop. The console looks like this :
So, it goes inside the function but then (I don't have much idea) "Cannot send function call result..." happens. Please help me regarding how to solve this.
This is my manifest.json
file :
"permissions": [
"storage",
"<all_urls>",
"tabs",
"activeTab"
],
"browser_action": {
"default_icon": "icons/pdf.ico",
"default_title": "My pdf",
"default_popup": "popup/addsite.html"
}
EDIT :-
I made a very simple extension consisting of only a background.js
file and copied the code from this site. Still then the only page where the function seems to work is the about:debugging
page of Firefox. So I don't understand what am I missing here?!