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)
Reporter | ||
Updated•11 years ago
|
Comment 1•11 years ago
|
||
Assignee | ||
Comment 2•11 years ago
|
||
Reporter | ||
Comment 3•11 years ago
|
||
Reporter | ||
Comment 4•11 years ago
|
||
Assignee | ||
Comment 5•11 years ago
|
||
Comment 6•11 years ago
|
||
Updated•11 years ago
|
Comment 7•11 years ago
|
||
Comment 10•10 years ago
|
||
Assignee | ||
Comment 11•10 years ago
|
||
Comment 12•10 years ago
|
||
Assignee | ||
Comment 13•10 years ago
|
||
Comment 14•10 years ago
|
||
Assignee | ||
Comment 15•10 years ago
|
||
Comment 16•10 years ago
|
||
Assignee | ||
Comment 17•10 years ago
|
||
Comment 19•10 years ago
|
||
Assignee | ||
Comment 20•10 years ago
|
||
Comment 21•10 years ago
|
||
Comment 22•10 years ago
|
||
Comment 23•10 years ago
|
||
Comment 24•10 years ago
|
||
Comment 25•9 years ago
|
||
Comment 27•9 years ago
|
||
Comment 29•9 years ago
|
||
Comment 30•9 years ago
|
||
Assignee | ||
Comment 31•9 years ago
|
||
Comment 32•9 years ago
|
||
Comment 33•9 years ago
|
||
Comment 34•8 years ago
|
||
Comment 35•8 years ago
|
||
Comment 36•8 years ago
|
||
Comment 37•8 years ago
|
||
Comment 38•8 years ago
|
||
Comment 39•8 years ago
|
||
Comment 40•8 years ago
|
||
Assignee | ||
Comment 41•8 years ago
|
||
Comment 42•8 years ago
|
||
Comment 43•8 years ago
|
||
Comment 44•8 years ago
|
||
Comment 45•8 years ago
|
||
Comment 46•7 years ago
|
||
Assignee | ||
Comment 47•7 years ago
|
||
Comment 48•7 years ago
|
||
Assignee | ||
Comment 49•7 years ago
|
||
Comment 50•7 years ago
|
||
Comment 51•6 years ago
|
||
Comment 52•6 years ago
|
||
Comment 53•6 years ago
|
||
Comment 54•6 years ago
|
||
Comment 55•6 years ago
|
||
Comment 56•6 years ago
|
||
Assignee | ||
Comment 57•6 years ago
|
||
Comment 58•6 years ago
|
||
Assignee | ||
Comment 59•6 years ago
|
||
Comment 60•6 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•6 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•6 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•6 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•5 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•5 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•5 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•5 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•5 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•5 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•5 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•5 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•5 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•5 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•5 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•5 years ago
|
||
Updated•5 years ago
|
Assignee | ||
Updated•5 years ago
|
Assignee | ||
Comment 76•5 years ago
|
||
Assignee | ||
Comment 77•5 years ago
|
||
Assignee | ||
Comment 78•5 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•5 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•5 years ago
|
||
An iframe would also solve my use case
Updated•5 years ago
|
Updated•5 years ago
|
Assignee | ||
Comment 81•5 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•5 years ago
|
||
Comment 83•5 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•5 years ago
|
||
Looks like Android is not shipping the same PDF viewer? I need to double-check what the setup is there.
Comment 85•5 years ago
|
||
Yeah, we don't ship pdf.js on android.
Assignee | ||
Comment 86•5 years ago
|
||
Relanding with the test skipped on Android.
Comment 87•5 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•5 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•5 years ago
|
||
Assignee | ||
Comment 90•5 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•5 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•5 years ago
|
||
Jason, thanks, that would be very helpful in terms of figuring out what's going on with that case...
Comment 93•5 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•5 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•5 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•5 years ago
|
||
That's not live on https://www.lenstock.com/FireFoxIFramePDFTest.aspx, right? I still see the display:none iframe there...
Comment 97•5 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•5 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•5 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•5 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•5 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•5 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•5 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•4 years ago
|
||
This bug is still present in Firefox 77. Only blank pages are printed.
Comment 106•4 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•4 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
•