Last Comment Bug 911444 - Error: Permission denied to access property 'print' on Firefox 23.0.1
: Error: Permission denied to access property 'print' on Firefox 23.0.1
Status: NEW
[pdfjs-c-integration]
:
Product: Firefox
Classification: Client Software
Component: PDF Viewer (show other bugs)
: 23 Branch
: x86_64 Windows 7
P3 normal with 27 votes (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
: Brendan Dahl [:bdahl] Away until Mar 29th
Mentors:
: 647658 1202197 1232097 (view as bug list)
Depends on: jsplugins-base
Blocks:
  Show dependency treegraph
 
Reported: 2013-08-31 01:06 PDT by justin.felisco
Modified: 2019-01-25 13:35 PST (History)
55 users (show)
bzbarsky: needinfo? (peterv)
bdahl: needinfo? (bzbarsky)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments

Description User image justin.felisco 2013-08-31 01:06:13 PDT
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.
Comment 1 User image Josh Matthews [:jdm] 2013-08-31 10:03:16 PDT
Can you provide a link that demonstrates this behaviour, or a code sample?
Comment 2 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2013-08-31 17:54:44 PDT
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.
Comment 3 User image justin.felisco 2013-08-31 22:39:07 PDT
(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.
Comment 4 User image justin.felisco 2013-08-31 22:40:15 PDT
(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'
Comment 5 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2013-09-01 10:18:58 PDT
> 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 User image Petruta Rasa [Away. Please needinfo? bogdan.maris@softvision.ro] 2013-09-02 04:57:02 PDT
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.
Comment 7 User image Tercio Gaudencio Filho 2013-11-29 11:36:31 PST
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0

Same issue here using a Mac.
Comment 8 User image vivek 2014-04-24 03:00:02 PDT
Any update on the resolution...I am facing this too..
Comment 9 User image Vijay 2014-06-05 12:23:39 PDT
Is anyone looking at this? Is there a workaround. Please note that the embedded frame is on the same domain.
Comment 10 User image Misido 2014-06-11 16:31:26 PDT
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?
Comment 11 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2014-06-11 18:43:57 PDT
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 User image Bobby Holley (:bholley) 2014-06-18 17:28:58 PDT
(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.
Comment 13 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2014-06-18 20:03:56 PDT
> 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 User image Bobby Holley (:bholley) 2014-06-19 11:22:50 PDT
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?
Comment 15 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2014-06-19 12:17:43 PDT
Yes, that would definitely fix this bug.
Comment 16 User image elic 2014-11-19 07:52:49 PST
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.
Comment 17 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2014-11-19 08:04:57 PST
It is, but dupping forward to here, since this bug has more info.
Comment 18 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2014-11-19 08:05:16 PST
*** Bug 647658 has been marked as a duplicate of this bug. ***
Comment 19 User image Sundar Racer 2014-12-15 03:10:25 PST
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
Comment 20 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2014-12-15 05:39:11 PST
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 User image Shriom 2015-01-16 13:17:13 PST
Hi,

May I know if there is any update on this issue.

Thanks,
Shriom
Comment 22 User image santy 2015-01-19 06:22:50 PST
Any fixes on this. ?
Comment 23 User image Bobby Holley (:bholley) 2015-01-20 08:57:25 PST
The bug to watch is bug 558184, which should get done (and possibly backported) this cycle.
Comment 24 User image jlt0022 2015-04-02 11:04:38 PDT
Been a few months, anyone found a workaround?
Comment 25 User image josgir 2015-07-29 06:21:42 PDT
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 26 User image Loic 2015-09-07 04:23:25 PDT
*** Bug 1202197 has been marked as a duplicate of this bug. ***
Comment 27 User image Aol11 2015-09-07 22:15:00 PDT
Disabling PDF.js doesn't work
Comment 28 User image Loic 2015-12-12 03:31:01 PST
*** Bug 1232097 has been marked as a duplicate of this bug. ***
Comment 29 User image Sanal 2015-12-14 20:41:28 PST
How come there is no proper solution for this after all these people reporting it.
Comment 30 User image grobi 2016-01-25 06:43:29 PST
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.
Comment 31 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2016-01-25 07:12:59 PST
> 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 User image Bobby Holley (:bholley) 2016-01-26 09:28:35 PST
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 User image aokegbile 2016-03-10 12:59:22 PST
I was able to get past this bug by updating my compatibility.js to latest version..
Comment 34 User image Sasko Mateski 2016-06-08 03:22:33 PDT
(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 User image style-orate 2016-09-07 13:03:59 PDT
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 User image Aleksander Machniak 2016-09-08 00:14:59 PDT
@style-orate, this way you print the whole page not the iframe. So, it does not fix anything.
Comment 37 User image Peter Pedaci 2016-09-30 16:52:41 PDT
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 User image Yannick Warnier 2016-11-05 10:02:08 PDT
+1
Comment 39 User image webmastercreations55 2016-12-18 18:49:37 PST
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 User image shaan.gidwani 2017-04-04 23:24:57 PDT
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.
Comment 41 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2017-04-05 06:14:22 PDT
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 User image shiv 2017-04-20 23:20:55 PDT
Any update on this? Our customer issues are rising to peak!!
Comment 43 User image stefan KRUGER 2017-04-26 03:22:56 PDT
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 User image shaan.gidwani 2017-04-26 04:07:37 PDT
#c35 will print whole page not specific iframe
Comment 45 User image stefan KRUGER 2017-04-26 04:37:42 PDT
Oops, you're write, my bad.
Comment 46 User image shaan.gidwani 2017-05-24 04:54:56 PDT
are we expect any date or its permanent bug in firefox which can not be resolved ?
Comment 47 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2017-05-24 07:18:27 PDT
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 User image arunavak111 2017-10-09 06:11:18 PDT
Is there any update on this issue? or any alternate solution to this?
Comment 49 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2017-10-09 11:38:34 PDT
Peter, do you know what the status there is?
Comment 50 User image cody 2018-03-20 07:26:01 PDT
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 User image shaan.gidwani 2018-07-17 06:51:46 PDT
(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 User image Jean Traullé 2018-10-06 03:29:12 PDT
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 User image Zmiy Gorinich 2018-11-22 07:38:52 PST
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 User image dotnetCarpenter 2018-11-22 15:09:25 PST
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 User image dotnetCarpenter 2018-11-23 05:17:30 PST
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 User image dotnetCarpenter 2018-11-23 07:37:35 PST
Actually pdf.js is already doing the right thing. We just need firefox to dispatch print() on the document that embeds pdf.js.
Comment 57 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2018-11-29 11:47:09 PST
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 User image Brendan Dahl [:bdahl] Away until Mar 29th 2018-11-29 17:30:21 PST
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?
Comment 59 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2018-11-29 18:42:14 PST
Peterv.
Comment 60 User image Christian Salazar 2019-01-13 17:13:35 PST
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 User image Christian Salazar 2019-01-13 17:29:49 PST
(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 User image william.randol 2019-01-22 08:11:09 PST
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.
Comment 63 User image Boris Zbarsky [:bzbarsky, bz on IRC] 2019-01-22 08:17:28 PST
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.

Note You need to log in before you can comment on or make changes to this bug.