Error: Permission denied to access property 'print' on Firefox 23.0.1
Categories
(Firefox :: PDF Viewer, defect, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox75 | --- | fixed |
People
(Reporter: justin.felisco, Assigned: bzbarsky)
References
Details
(Whiteboard: [pdfjs-c-integration])
Attachments
(4 files, 1 obsolete file)
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36 Steps to reproduce: I used IFrame to display the PDF and the PDF is located on the same host. I'm using the PDF.js to display it, but I'm not using its print button. Instead I created a another print button to trigger the print feature. But I received error. But on other browsers it is working fine. Actual results: When I looked at on firebug, I received this message "Error: Permission denied to access property 'print'" Expected results: PDf inside the IFrame should be printed.
Reporter | ||
Updated•10 years ago
|
Comment 1•10 years ago
|
||
Can you provide a link that demonstrates this behaviour, or a code sample?
![]() |
Assignee | |
Comment 2•10 years ago
|
||
It should be pretty straightforward: <iframe src="some-same-origin.pdf"></iframe> <script> window.onload = function () { try { frames[0].print(); } catch (e) { alert("Exception thrown: " + e); } } </script> The issue is that the built-in PDF renderer creates a privileged document for the PDF, and the caller is not allowed to get the .print of a privileged window. If, instead, we had used a full-page plug-in to render the PDF, the access here would be same-origin... This is an issue in how pdf.js is hooked up to the docshell.
Reporter | ||
Comment 3•10 years ago
|
||
(In reply to Josh Matthews [:jdm] from comment #1) > Can you provide a link that demonstrates this behaviour, or a code sample? 1st test: var pdfFrame = document.getElementById('print_pdf_holder'); pdfFrame.focus(); pdfFrame.contentWindow.print(); 1st test result: Error: Permission denied to access property 'print' 2nd & 3rd test: window.frames[0].focus(); window.frames[0].print(); window.frames.focus(); window.frames.print(); 2nd test result: Both shows Error: Permission denied to access property 'print' But the in other browser, these test are working fine. Firefox 23.0.1 shows this error message.
Reporter | ||
Comment 4•10 years ago
|
||
(In reply to Boris Zbarsky [:bz] from comment #2) > It should be pretty straightforward: > > <iframe src="some-same-origin.pdf"></iframe> > <script> > window.onload = function () { > try { > frames[0].print(); > } catch (e) { > alert("Exception thrown: " + e); > } > } > </script> > > The issue is that the built-in PDF renderer creates a privileged document > for the PDF, and the caller is not allowed to get the .print of a privileged > window. If, instead, we had used a full-page plug-in to render the PDF, the > access here would be same-origin... > > This is an issue in how pdf.js is hooked up to the docshell. I've tried your code snippet. But it returns Error: Permission denied to access property 'print'
![]() |
Assignee | |
Comment 5•10 years ago
|
||
> I've tried your code snippet. But it returns Error: Permission denied to access property > 'print' Yes, of course. My code snippet was a reply to comment 1.
Comment 6•10 years ago
|
||
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0 (20130901030218) I encounter the following error using the code from Comment 2 on latest Nightly and Fx 23.0.1 : Exception thrown: Error: Permission denied to access property 'print' When using the code from Comment 3, the print dialog is opened, but a blank page is printed. Marking this as NEW.
Updated•10 years ago
|
Comment 7•10 years ago
|
||
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0 Same issue here using a Mac.
Is anyone looking at this? Is there a workaround. Please note that the embedded frame is on the same domain.
Comment 10•9 years ago
|
||
Wear over a month trying to give solution to this, today 2014-06-11 I have updated my Firefox to version 30.0 and the error still persists; Firefox is my preferred development for electronic invoice and my only alternative seems to be Chrome browser. Please someone who gave the solution?
![]() |
Assignee | |
Comment 11•9 years ago
|
||
Bobby, could we make this work somehow? This is a case where effectively the fact that pdfjs is running with some weird principal is surprising users because that's not what a plugin document would be doing... Can we make print() callable cross-origin in this one special case? Ideally only if the actual origin we were loaded from is same-origin with the caller.
Comment 12•9 years ago
|
||
(In reply to Boris Zbarsky [:bz] from comment #11) > Bobby, could we make this work somehow? This is a case where effectively > the fact that pdfjs is running with some weird principal is surprising users > because that's not what a plugin document would be doing I don't think we should make this work - it doesn't in other UAs, and the fact that we have a subframe here is an implementation detail. See my suggestion on bug 558184 comment 57 for a proposed architecture going forward - we should avoid exposing the existence of a descendant docshell entirely.
![]() |
Assignee | |
Comment 13•9 years ago
|
||
> it doesn't in other UAs Does it not? <iframe src="test.pdf"></iframe> <input type="button" value="click me" onclick="frames[0].print();"> </script> works fine for me in Chrome at first glance as long as test.pdf is an actual PDF. Make sure to run that over http://, not file://, though. > and the fact that we have a subframe here is an implementation detail No, the subframe is in the page markup. > we should avoid exposing the existence of a descendant docshell entirely. You're not allowed to do that for <iframe>.
Comment 14•9 years ago
|
||
Oh, I was confused about the different semantics of <iframe> and <embed>/<object>. Reading the spec though, it looks like this should be fine - we should just do the normal plugin document thing for the iframe, and let the semantics in bug 558184#c57 work their magic in the <embed> inside the plugin document. Does that sound good?
![]() |
Assignee | |
Comment 15•9 years ago
|
||
Yes, that would definitely fix this bug.
Comment 16•9 years ago
|
||
I think this is a duplicate of https://bugzilla.mozilla.org/show_bug.cgi?id=647658 but don't want to mark it as such just in case I'm wrong.
![]() |
Assignee | |
Comment 17•9 years ago
|
||
It is, but dupping forward to here, since this bug has more info.
Comment 19•9 years ago
|
||
Hi, This issue is reported an year ago, Is there any update on this?, please update the status of the issue. Thanks in advance Sundar Racer
![]() |
Assignee | |
Comment 20•9 years ago
|
||
The status is that bug 558184 needs to be fixed first; see comment 14. That should happen sometime in the next few months, hopefully.
Comment 21•9 years ago
|
||
Hi, May I know if there is any update on this issue. Thanks, Shriom
Comment 22•9 years ago
|
||
Any fixes on this. ?
Comment 23•9 years ago
|
||
The bug to watch is bug 558184, which should get done (and possibly backported) this cycle.
Comment 24•9 years ago
|
||
Been a few months, anyone found a workaround?
Comment 25•8 years ago
|
||
Maybe someone useful this solution "you have to disable the bugged and native PDF viewer (pdf.js) in about:config. Set the pdfjs.disabled property to true and you will see the print window appearing using your script." http://stackoverflow.com/questions/15011799/firefox-19-print-pdf-from-javascript#answer-21500997 and more http://stackoverflow.com/questions/15011799/firefox-19-print-pdf-from-javascript#answer-25490208
Comment 27•8 years ago
|
||
Disabling PDF.js doesn't work
Comment 29•8 years ago
|
||
How come there is no proper solution for this after all these people reporting it.
Comment 30•8 years ago
|
||
I receive a 'Error: Permission denied to access property "print"' too, when trying to print a PDF.js frame (or window). Is there any reason why this should not be possible? What's the "permission" gap mentioned in the error message? As same-origin is affective, I can't see how "allow javascript print" would annoy/exploit people.
![]() |
Assignee | |
Comment 31•8 years ago
|
||
> What's the "permission" gap mentioned in the error message? In brief, the actual browser-provided scripts in the pdf.js frame are not running with the origin of the website the PDF came from. They're running with an origin that has more privileges that are needed for pdf.js to work. So when website code tries to touch the object in that frame it gets a security exception. This also answers comment 29: there is no proper solution yet because fixing this requires significantly rearchitecting how pdf.js works unless the security model is changed. Bobby, given the jsplugins back-burnering situation, I'd really like us to think seriously about allowing cross-origin calls to print() in this specific case.
Comment 32•8 years ago
|
||
Spoke with jst about this today. Peter is really on the cusp of landing his stuff (which was ready to land last month but got broken by APZ), so we should be super close here.
Comment 33•8 years ago
|
||
I was able to get past this bug by updating my compatibility.js to latest version..
Comment 34•7 years ago
|
||
(In reply to aokegbile from comment #33) > I was able to get past this bug by updating my compatibility.js to latest > version.. Can you advise me on how to update compatibility.js to latest version? Im using Mozila Firefox 47.0 on Windows.
Comment 35•7 years ago
|
||
the truth I achieved so much after reading blogs , I could make printing files with the following code I hope will be helpful ... file html: <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" /> <script > $(document).ready(function() { $(".pdf-print").live("click",function () { $('#visualizador-pdf').get(0).contentWindow.focus(); window.print(); }); }); </script> </head> <body> <div id="visualizador-pdf-div"> <iframe id="visualizador-pdf" name="visualizador-pdf" src="pdf/Comparendo_Aprobado_1491.pdf" height="400" width="521"></iframe> <a class="pdf-print" id="wp-submit">Imprimir</a> </div> </body>
Comment 36•7 years ago
|
||
@style-orate, this way you print the whole page not the iframe. So, it does not fix anything.
Comment 37•7 years ago
|
||
Three years since the first report, 9 months after being 'super close' ... will we see a solution to this before ze germans get here?
Comment 38•7 years ago
|
||
+1
Comment 39•7 years ago
|
||
We should have figured out a fix for this now... Please fix this asap, it is a very vital function and the only option for cross browser compatibility of creating a print button.
Comment 40•7 years ago
|
||
I dont know why mozilla is starching this issue long. We have same functions in chrome and IE but for firefox iframe is not working. neither we can set option from programing to set the pdf viewer so that same printout is coming from all the browsers. Please fix this this is height of any issue. Please let us know if this is issue will not resolved in the future so that we can advice the customer that our web is not compatible in firefox anymore so that its big relief for us.
![]() |
Assignee | |
Comment 41•7 years ago
|
||
The fix is being worked on; it's to switch to a different PDF viewer with a different security setup that does not have this issue.
Comment 42•7 years ago
|
||
Any update on this? Our customer issues are rising to peak!!
Comment 43•7 years ago
|
||
You can use the solution in #c35 (https://bugzilla.mozilla.org/show_bug.cgi?id=911444#c35) for now, it's working for me. ;)
Comment 44•7 years ago
|
||
#c35 will print whole page not specific iframe
Comment 45•7 years ago
|
||
Oops, you're write, my bad.
Comment 46•6 years ago
|
||
are we expect any date or its permanent bug in firefox which can not be resolved ?
![]() |
Assignee | |
Comment 47•6 years ago
|
||
There isn't a clear date yet; there are a lot of issues left to fix with the new PDF viewer. But it's being actively worked on. Chances are it's several more months before it's ready.
Comment 48•6 years ago
|
||
Is there any update on this issue? or any alternate solution to this?
![]() |
Assignee | |
Comment 49•6 years ago
|
||
Peter, do you know what the status there is?
Comment 50•6 years ago
|
||
Kind of insane that 5 years later this is still a bug, please provide a status or at least say you are not going to fix it?
Comment 51•5 years ago
|
||
(In reply to cody from comment #50) > Kind of insane that 5 years later this is still a bug, please provide a > status or at least say you are not going to fix it? Yes, its very bad limitation of firefox for any simple developer. We have many plugins which says that our functionality of print will works fine in all the browser except firefox so please use chrome for better result. ex: See the comment in "http://printjs.crabbly.com/". This plugin very useful for print anything and any part of the website but its not working in firefox. Firefox currently doesn't allow printing PDF documents using iframes. There is an open bug in Mozilla's website about this. When using Firefox, Print.js will open the PDF file into a new tab. Very bad support . After 5 year we are not able to get the fix..... very bad
Comment 52•5 years ago
|
||
Seems like a duplicates of #874200 I am also using printJS and it would be really great if this issue were fixed ;) Any progress from anyone on this ?
Comment 53•5 years ago
|
||
Any progress with this Bug? 5 years is not enough to resolve problem? or may be it is not bug , some special feature?
Comment 54•5 years ago
|
||
I finally created an issue at the root cause project. This bug is due to pdf.js https://github.com/mozilla/pdf.js/issues/10290
Comment 55•5 years ago
|
||
After a lengthy chat in the pdf.js github issue it has become clear that: **There is no way to create a work-around Firefox security policy in pdf.js, when print() is called. Hence print() will always throw in Firefox because of how pdf.js is embedded in Firefox.** I've asked for guidance on how to solve this issue in Firefox. https://github.com/mozilla/pdf.js/issues/10290#issuecomment-441238004
Comment 56•5 years ago
|
||
Actually pdf.js is already doing the right thing. We just need firefox to dispatch print() on the document that embeds pdf.js.
![]() |
Assignee | |
Comment 57•5 years ago
|
||
I should note that even if the security policy changes to allow calling window.print() here, that will likely not print the PDF usefully without various other work...
Comment 58•5 years ago
|
||
I think the first step forward here is to decide if we are keeping the js plugins code. If we are, we could potentially migrate pdf.js to it. However, I was pinged a few months ago about someone wanting to remove the js plugins code, so I'm really not sure about the status of it. I'd think peterv would know the most, but he's already need info'd on this bug. Boris, any thoughts on who else would know about js plugins?
![]() |
Assignee | |
Comment 59•5 years ago
|
||
Peterv.
Comment 60•5 years ago
|
||
dear developpers,
i know it is a old issue but im still having problems when using this feature, the good news is: i have a stable workaround.
CASE: (works on chrome, but fails on firefox):
<iframe id='x1' src='/path/to.pdf'></iframe>
<script>
document.getElementById('x1').contentWindow.print();
// dialog window pop ups on chrome, not firefox.
</script>
WORKAROUND:
Build the IFRAME from a ajax call (instead of adding the "<iframe>.." directly into our html).
<div id='pdf'>...</div>
<script>
setTimeout(function(){
$.ajax({ cache: false, type: 'post', url: 'some/path/to/buildIframe.php',
success: function(resp) {
$('#pdf').html(resp);
document.getElementById('x1').contentWindow.print();
}
});
}, 100);
</script>
on the server side, (using php as an example) :
<?php
// file: buildIframe.php
// do your own implementation to respond the ajax request ...
echo "<iframe id='x1' src='/path/to.pdf'></iframe>";
?>
Comment 61•5 years ago
|
||
(In reply to Christian Salazar from comment #60)
dear developpers,
i know it is a old issue but im still having problems when using this feature, the good news is: i have a stable workaround.
CASE: (works on chrome, but fails on firefox):
<iframe id='x1' src='/path/to.pdf'></iframe> <script> document.getElementById('x1').contentWindow.print(); // dialog window pop ups on chrome, not firefox. </script>
WORKAROUND:
Build the IFRAME from a ajax call (instead of adding the "<iframe>.." directly into our html).
<div id='pdf'>...</div> <script> setTimeout(function(){ $.ajax({ cache: false, type: 'post', url: 'some/path/to/buildIframe.php', success: function(resp) { $('#pdf').html(resp); document.getElementById('x1').contentWindow.print(); } }); }, 100); </script>
on the server side, (using php as an example) :
<?php // file: buildIframe.php // do your own implementation to respond the ajax request ... echo "<iframe id='x1' src='/path/to.pdf'></iframe>"; ?>
im sorry, i forget to metion this:
wrap this call:
document.getElementById('x1').contentWindow.print();
with:
setTimeout(function(){ ... }, 10);
the "10" ms value is needed, when too large then it wont work..
Comment 62•5 years ago
|
||
This issue has reared it's ugly head once again. I have designed a beautifully elegant solution to printing reports in a web application that involves loading a pdf into a hidden iframe and printing from that. Wonderful works perfectly in Chrome and even in Edge. Alas, Firefox you wound me. I took to the internet sure I had done something wrong. Ney, an error from over 8 years ago plagues us. I guess this is just a wordy +1 post, but without these, I don't believe that this issue will be resolved. Thank you for your time.
![]() |
Assignee | |
Comment 63•5 years ago
|
||
Actually, the +1 posts will make it harder to resolve the issue, because they make it harder to find the technical discussion....
I should also note that the solution in comment 62 may not work so great for users who turn off the built-in PDF viewer in their browser.
Comment 64•4 years ago
|
||
Another year has gone by with no end in sight on a 6 1/2 year old, highly problematic bug. As has been stated many, many times, this is rather critical functionality that only Firefox has an issue with and has not prioritized fixing over the past 7 years, despite promises to the contrary. Like many others, I find myself in the unfortunate position of potentially having to explain to our clients that they will need to avoid Firefox in order to use our applications.
![]() |
Assignee | |
Comment 65•4 years ago
|
||
Just in case it wasn't clear, fixing this more or less requires a complete rewrite of the PDF viewer. And yes, it's been hard to prioritize that because for most consumers of the PDF viewer this is not the most pressing problem. I sympathize with the cases when it is, and I've been spending some time thinking about this, but I really haven't had much time to devote to this.
I will try to see if I can increase the visibility of this, though.
![]() |
Assignee | |
Comment 66•4 years ago
•
|
||
Actually, there might be ways to do this without a complete rewrite. So here's a specific question: if the print() call were implemented internally in terms of an async postMessage() to the pdf document that then triggers exactly the same codepath as clicking the "print" button in the iframe/window showing the PDF, would that address the use cases people have for this? (It still wouldn't work for users who disable the built-in PDF viewer, of course...)
Comment 67•4 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #66)
Actually, there might be ways to do this without a complete rewrite. So here's a specific question: if the print() call were implemented internally in terms of an async postMessage() to the pdf document that then triggers exactly the same codepath as printing the "print" button in the iframe/window showing the PDF, would that address the use cases people have for this? (It still wouldn't work for users who disable the built-in PDF viewer, of course...)
I thought the issue was strictly related to how the PDF viewer is embedded in firefox (resource://pdf.js)?
That means that the firefox pdf.js version will break pdf's (.print()
) included in an iframe.
pdf.js works in all browsers and also in firefox if included by the web author (in contrast to the firefox browser).
However, that means that the user has to download pdf.js, even though it is bundled with the firefox browser...
Main focus appears to be, embed pdf.js in Firefox in a way that does NOT prevent calls to .print()
.
Embedding pdf.js in a semi-privileged document was a big mistake in the first place
https://github.com/mozilla/pdf.js/issues/10290#issuecomment-441236088
- This bug is a regression -
.print()
worked in firefox before pdf.js was embedded. - This bug is a parity issue -
.print()
works in all other browsers but firefox.
![]() |
Assignee | |
Comment 68•4 years ago
|
||
I thought the issue was strictly related to how the PDF viewer is embedded in firefox (resource://pdf.js)?
Yes, but changing that is ... complicated, because the script actually needs some special privileges to do some of the things it's doing, as I understand.
pdf.js works in all browsers and also in firefox if included by the web author
My understanding (which could be wrong!) is that there are some functionality restrictions when used this way.
Main focus appears to be, embed pdf.js in Firefox in a way that does NOT prevent calls to .print().
There is no resourcing for that and won't be for the foreseeable future. Waiting on that resourcing is where we've been for how long now?
I would still appreciate answers to my specific question from comment 66. Just repeating that this is problem is not helpful; we all know it's a problem here.
Comment 69•4 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #66)
Actually, there might be ways to do this without a complete rewrite. So here's a specific question: if the print() call were implemented internally in terms of an async postMessage() to the pdf document that then triggers exactly the same codepath as printing the "print" button in the iframe/window showing the PDF, would that address the use cases people have for this? (It still wouldn't work for users who disable the built-in PDF viewer, of course...)
Yes, if I'm understanding, I believe that would work for my use case.
Comment 70•4 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #66)
Actually, there might be ways to do this without a complete rewrite. So here's a specific question: if the print() call were implemented internally in terms of an async postMessage() to the pdf document that then triggers exactly the same codepath as clicking the "print" button in the iframe/window showing the PDF, would that address the use cases people have for this? (It still wouldn't work for users who disable the built-in PDF viewer, of course...)
Yes. That should work. For my use-cases, using "the hidden iframe trick" as documented numerous places around the Internet, would suffice.
Here is one such example: https://www.sitepoint.com/load-pdf-iframe-call-print/
![]() |
Assignee | |
Comment 71•4 years ago
|
||
One more question for people. Is this just needed for iframes, or also for windows opened with window.open()
? There are some security considerations that I'm trying to sort out and knowing that would help with what possible solutions are OK.
Comment 72•4 years ago
|
||
Imo, 99% cases is iframes. This is when you have Print button on the parent page and pdf preview in iframe. I also think that most of that is NOT cross-domain. No comments here mention window.open().
Comment 73•4 years ago
|
||
Personally I just want Print.js ( https://printjs.crabbly.com/ ) to work in Firefox like it does with Google. IIRC Print.js uses a hidden iframe.
Comment 74•4 years ago
|
||
Both would be useful, though I must admit that an iframe-only solution would solve my use case at this time.
![]() |
Assignee | |
Comment 75•4 years ago
|
||
Updated•4 years ago
|
![]() |
Assignee | |
Updated•4 years ago
|
![]() |
Assignee | |
Comment 76•4 years ago
|
||
![]() |
Assignee | |
Comment 77•4 years ago
|
||
![]() |
Assignee | |
Comment 78•4 years ago
|
||
The method is exposed only if the consumer has the same principal as the PDF
would have if it were not getting the PDF viewer treatment.
The method just calls the print() method in the PDF viewer window.
It's enough to expose this on OuterWindowProxy, not RemoteOuterWindowProxy,
because we ensure PDF documents end up in the process they would have been in
based on their pre-PDF-viewer principal.
![]() |
Assignee | |
Comment 79•4 years ago
|
||
This ensures we never have a RemoteWindowProxy from a page to a PDF viewer that
should have been same-origin with it.
This does not disclose any server-side information that would not ideally be
available anyway (if the PDF viewer were actually made same-origin with the
embedding page, say, when the PDF URL is same-origin).
In case of full-content-process security compromises, it doesn't look like the
APIs exposed to the PDF viewer allow anything that could not be done via other
methods available during such a compromise.
Comment 80•4 years ago
|
||
An iframe would also solve my use case
Updated•4 years ago
|
Updated•4 years ago
|
![]() |
Assignee | |
Comment 81•4 years ago
|
||
If people want to try builds with the above patches applied, they are available at:
- Win64: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/RrOIcl5jSlSImviJ85SKFA/runs/0/artifacts/public/build/target.zip
- Mac: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/JVdOK5R3QIqw2H0Y9W34WA/runs/0/artifacts/public/build/target.dmg
- Linux64: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/G60jSb-5Rd6tvWRe4HJm8w/runs/0/artifacts/public/build/target.tar.bz2
Comment 82•4 years ago
|
||
Pushed by bzbarsky@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/fd2e3e8728d9 part 1. Factor out the "is pdf viewer" code so we can reuse it. r=bholley https://hg.mozilla.org/integration/autoland/rev/b96d0a37ed1a part 2. Allow sending an nsIPrincipal in a variant over IPC. r=nika https://hg.mozilla.org/integration/autoland/rev/a32592af0b11 part 3. Store the principal a PDF viewer document would have had if the PDF viewer had not messed with the principal. r=bdahl,bholley https://hg.mozilla.org/integration/autoland/rev/d156bbaabbd5 part 4. Expose a print method on PDF viewer windows. r=bholley
Comment 83•4 years ago
|
||
Backed out 4 changesets (bug 911444) for Mochitest failures in dom/base/test/test_pdf_print.html. CLOSED TREE
Log:
https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=290261094&repo=autoland&lineNumber=3058
Backout:
https://hg.mozilla.org/integration/autoland/rev/baa43fa6e5d2a55a993dd47594baf862dfb5893d
![]() |
Assignee | |
Comment 84•4 years ago
|
||
Looks like Android is not shipping the same PDF viewer? I need to double-check what the setup is there.
Comment 85•4 years ago
|
||
Yeah, we don't ship pdf.js on android.
![]() |
Assignee | |
Comment 86•4 years ago
|
||
Relanding with the test skipped on Android.
Comment 87•4 years ago
|
||
If people want to try builds with the above patches applied, they are available at:
I just tried it out and got "The page at resource://pdf.js says: Warning: The PDF is not fully loaded for printing", then the print dialog, which printed an empty page. For all the other browsers/plugins, we just have an addEventListener "load". If you've created a special print function, you'll need to tie it to the render promise to put it on parity with other browsers.
When I added a 10 second setTimeout, it came up with the print dialog before the "The PDF is not fully loaded for printing" message. It printed an empty page. Note, it took 604ms to download the PDF.
So, closer, but not quite there.
![]() |
Assignee | |
Comment 88•4 years ago
|
||
Jason, just so I understand, in your case the print function is not being called from a user clicking a button, but something more like this:
<iframe src="something.pdf" onload="this.contentWindow.print()"></iframe>
?
Comment 89•4 years ago
|
||
Pushed by bzbarsky@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/c27d113d6f61 part 1. Factor out the "is pdf viewer" code so we can reuse it. r=bholley https://hg.mozilla.org/integration/autoland/rev/de114a360687 part 2. Allow sending an nsIPrincipal in a variant over IPC. r=nika https://hg.mozilla.org/integration/autoland/rev/c0e52b90c522 part 3. Store the principal a PDF viewer document would have had if the PDF viewer had not messed with the principal. r=bdahl,bholley https://hg.mozilla.org/integration/autoland/rev/e681c2a6d146 part 4. Expose a print method on PDF viewer windows. r=bholley
![]() |
Assignee | |
Comment 90•4 years ago
|
||
On the assumption that the answer to comment 88 is "yes", I filed bug 1618553.
That said, I'm surprised a 10s timeout was still not enough, unless this was a quite large PDF or something else is broken. A link to a testcase would be quite helpful.
Comment 91•4 years ago
|
||
That said, I'm surprised a 10s timeout was still not enough, unless this was a quite large PDF or something else is broken. A link to a testcase would be quite helpful.
That's why I mentioned that it only took 604ms to download the pdf. It's a single page, 55,211 bytes.
I'm unfortunately in the process of trying to rebuild an old project from 2002, that's how I landed in the "oh, it doesn't work for firefox, users were told to use anything but, unless they don't mind going to the new tab 150 times a day, hitting print, hitting ok, then closing the tab to go to the next set of orders/reports" and went on a hunt on how to fix it and found this post. I'll see if I can convince my supervisor to allow me to create a test page and put it live.
![]() |
Assignee | |
Comment 92•4 years ago
|
||
Jason, thanks, that would be very helpful in terms of figuring out what's going on with that case...
Comment 93•4 years ago
|
||
https://www.lenstock.com/FireFoxIFramePDFTest.aspx click the "details" button next to a garbage order, then below will be several different "print" buttons. The regular "print" button has how we currently handle firefox by window.open and after 3 seconds it tries to fire print() in a try catch block(that with the test version occasionally works now)
![]() |
Assignee | |
Comment 94•4 years ago
|
||
Thanks, that helps a lot. The issue is the "display:none" on the iframe; I filed bug 1618621 on that, and bug 1618626 to track this set of issues in general.
As a workaround, removing the display:none might help, but the timing of the load event is still wrong for your purposes, of course...
Comment 95•4 years ago
|
||
I removed the display:none and replaced it with the iframe being underneath the header with a z-index and low max height/widths. Didn't make any sort of difference, even to the 10 second timeout.
![]() |
Assignee | |
Comment 96•4 years ago
|
||
That's not live on https://www.lenstock.com/FireFoxIFramePDFTest.aspx, right? I still see the display:none iframe there...
Comment 97•4 years ago
|
||
Correct, not live. I changed it on my development machine to test it, didn't make a difference, so didn't push it out(that, and since the iframe is sitting on the masterpage, it would change for our live users using the rest of the site too and I'm not real hip on having to retest all the other browsers again).
![]() |
Assignee | |
Comment 98•4 years ago
|
||
Understood. I just haven't had luck so far reproducing the problem with a delay and without the display:none, so trying to figure out what other issue you might be running into...
Comment 99•4 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/c27d113d6f61
https://hg.mozilla.org/mozilla-central/rev/de114a360687
https://hg.mozilla.org/mozilla-central/rev/c0e52b90c522
https://hg.mozilla.org/mozilla-central/rev/e681c2a6d146
Comment 100•4 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #98)
Understood. I just haven't had luck so far reproducing the problem with a delay and without the display:none, so trying to figure out what other issue you might be running into...
I've gone ahead and updated it to use a different iframe that's an absolute position at the top under the header with a z-index with at least a little size. I can see it when I hide the header. Doesn't change the results. Note, the results I'm looking at is from the link provided 6 days ago for 75.0.0.7357.
Comment 101•4 years ago
|
||
Picked up todays nightly 75.0.0.7363 and have the same issue. If I use the non-delay print dialog, I get the print dialog then the not fully rendered message. If I use the delay print buttons, I get the not fully rendered message then the print dialog. In all cases it prints an empty sheet of paper(due to the not fully rendered bit).
![]() |
Assignee | |
Comment 102•4 years ago
|
||
Fun. The small size is the issue; I filed bug 1618955. Thank you very much for updating the page!
I think just doing a normal-sized absolutely positioned iframe with "visibility: hidden" should do the right thing, at least in my local testing. But obviously we should fix the small size thing too...
Comment 103•4 years ago
|
||
I've made this tests in Firefox Nightly / Linux / 75.0a1 (2020-02-28) (64-bit)
iframe with Big Size and visibility:hidden
Synchronous printing in the iframe.onload
event
- Warning: The PDF is not fully loaded
- print dialog
- Blank PDF
Asynchronous printing (with enough delay) in the iframe.onload
event
- print dialog
- PDF OK :+1:
iframe with No Size
TL;DR In both cases I get a Blank PDF, but in the Asynchronous one the printing dialog appears first, and the warning message after
Synchronous printing in the iframe.onload
event
- Warning: The PDF is not fully loaded
- print dialog
- Blank PDF
Asynchronous printing (with enough delay) in the iframe.onload
event
- print dialog
- Warning: The PDF is not fully loaded
- Blank PDF
print with sufficient delay:
Comment 105•3 years ago
|
||
This bug is still present in Firefox 77. Only blank pages are printed.
Comment 106•3 years ago
|
||
The document is printed, but an error falls in the console "SecurityError: Permission denied to access property "document" on cross-origin object"
Comment 107•3 years ago
|
||
I've had a brief play with printing PDF in current release Firefox (version 80). My findings so far:
- An extra delay after the iframe element's
load
event is required. For a small PDF on my modern PC, 1000ms was enough but 100ms was not. I have not further information (yet) on what is a reliable delay. - I'm pretty sure at least some of the PDF has to be visible for printing it to work. Hiding using CSS
display
orvisibility
, or via positioning the iframe outside of the visible page area using absolute positioning ortransform
, does not work ("The PDF is not fully loaded for printing" in most cases). - Keeping the iframe visible and setting
opacity: 0
works. - After the call to the iframe window object's
print()
method, removing the iframe element immediately or even after a brief delay results in the printing dialog to hang indefinitely. However, things are fine if you hide the iframe using any of the previously-mentioned methods at this point.
I think I have a workable solution for my needs using the following:
- Display the iframe in the visible area of the page with a reasonable size to ensure some of the PDF document other than its toolbar is visible. 80px high seems to be enough. I'm not sure there's any reason to restrict it to that though.
- Make the iframe invisible to the user using
opacity: 0
. - Once the iframe's
load
event fires, wait for some interval (I'll need to experiment with larger PDFs to pin this down) before callingprint()
on the iframe's window object - After the
print()
call, setdisplay: none
on the iframe.
I created a gist of my working code: https://gist.github.com/timdown/cfacd32f6b5e439bb02aaf142343ce4c
Description
•