Problem with jspdf.plugin.addimage.js in latest version of chrome
When I try to add a large image in the latest version of chrome (Version 42.0.2311.90 (64-bit)) the pdf is not displayed, only a grey background (if i add small images i have no problem). In older versions it works fine. Console log shows:
Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' chrome://resources". detectEval @ polymer.js:4235 extensions::lastError:133 Unchecked runtime.lastError while running mimeHandlerPrivate.getStreamInfo: Streams are only available from a mime handler view guest. at main (chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/main.js:91:31) at chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/main.js:96:3 at chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/main.js:97:3reportIfUnchecked @ extensions::lastError:133 pdf.js:75 Uncaught (in promise) TypeError: Cannot read property 'originalUrl' of undefined
What can I do? Any ideas about it?
Thanks.
I have the same problem.. In Firefox it seems to work fine. Maybe it's a bug in chrome ?
I opened a bug report for it (https://code.google.com/p/chromium/issues/detail?id=478389)
I used the "object" tag to display the PDF before chrome came up with his new update (42.0). Now I am using the "iframe" tag, because "object" gets no longer supported for that.
I need a quick and stable solution. If someone has more information, please share...
Thanks
Also having the same problem. Worked great until I updated chrome today.. Now i'm in a rush to get this working again.
Experiencing same issue on MAC and PC versions of chrome. As a hot fix, changed from
doc.output('dataurlnewwindow');
to
doc.save('filename.pdf');
same issue here. this is related to a recent update on chrome. Problem is that there is no way to revert back to a previous version of chrome.
What libraries are you using on the page? I see polymer.js mentioned in the error message?
On Fri, 24 Apr 2015 at 14:57 grex84 [email protected] wrote:
same issue here. this is related to a recent update on chrome. Problem is that there is no way to revert back to a previous version of chrome.
— Reply to this email directly or view it on GitHub https://github.com/MrRio/jsPDF/issues/481#issuecomment-95941993.
I am using jspdf.js and jspdf.plugin.addimage.js, but in order to get this working again I added temporarily FileSaver.js and changed doc.output('dataurlnewwindow') to doc.save('filename.pdf'); I don't know what is Polymer.js because it doesn't exist in my project...
Oh, weird that it's in the error message. I'm googling but can't find anything, can you chuck an example page up somewhere with the problem?
On Fri, 24 Apr 2015 at 16:05 cosf87 [email protected] wrote:
I am using jspdf.js and jspdf.plugin.addimage.js, but in order to get this working again I added temporarily FileSaver.js and changed doc.output('dataurlnewwindow') to doc.save('filename.pdf'); I don't know what is Polymer.js because it doesn't exist in my project...
— Reply to this email directly or view it on GitHub https://github.com/MrRio/jsPDF/issues/481#issuecomment-95957922.
Apparently the exception is thrown in an internal/build-in chrome extension used to display PDFs:
https://codereview.chromium.org/96233002
In fact, Chrome is known to have issues handling very long base64 URIs, and naturally slightly unstable with regards to JS memory usage.
For those who would like to preview the PDF rather than saving it, i'd suggest stop using doc.output('dataurlnewwindow'); and instead do:
var bloburi = doc.output('bloburi');
window.open(bloburi);
NB: This returns an URI created with createObjectURL which you have to free using revokeObjectURL
@cosf87
I'd rather use one of the files available on the dist folder (either jspdf.min.js or jspdf.debug.js), that already includes basic dependencies (such as FIleSaver.js)
@diegocr Your code to preview the PDF works fine!! Thanks for your advice, now I'm using jspdf.min.js file from dist folder.
Is the approach mentioned by @diegocr the recommended way to do this, or is it a temporary workaround until a better solution can be coded into this library?
Thanks for the solution!
@diegocr your solution didn't work for me... I just get a blank grey screen. Any ideas? I've seen some people claiming this is due to Chrome recently having removed some built-in PDF plugins.
I'm having this problem, I tried @diegocr 's solution in this fiddle to no avail... It works in Mozilla though, even with doc.output('dataurlnewwindow'); ...
@mariadelmarq Chrome has been really annoying about this whole thing. They actually flipped and only seems to work with doc.save now, at least as of the last version. What I ended up doing is detecting if Chrome is active and doing different things if chrome is active.
if (is_chrome){
doc.save("report.pdf");
//otherwise view it
} else{
doc.output('dataurl')
}
Thank you, @JulianKingman. I read that browser detection is highly discouraged, and that feature detection should be used instead. Do you happen to know how to implement that in this case?
@mariadelmarq I read a similar thing. I think the reason it's discouraged is because it's a messy way of doing things in most cases, that is usually it's related to a particular feature that may be relevant across more than one browser, rather than related to the browser itself. If there's a way to do this with feature detection, I don't know it, sorry! That said, I think because the problem is with the browser, browser detection may be a suitable solution. I could be wrong?
Thank you so much for your help, @JulianKingman :+1:
You’re welcome :)
On July 31, 2015 at 2:00:47 AM, mariadelmarq ([email protected]) wrote:
Thank you so much for your help, @JulianKingman
— Reply to this email directly or view it on GitHub.
Probably solved.