Error: Permission denied to access property 'print' on Firefox 23.0.1

NEW
Unassigned

Status

()

Firefox
PDF Viewer
P3
normal
4 years ago
2 months ago

People

(Reporter: justin.felisco, Unassigned)

Tracking

23 Branch
x86_64
Windows 7
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [pdfjs-c-integration])

(Reporter)

Description

4 years ago
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

4 years ago
Priority: -- → P3

Comment 1

4 years ago
Can you provide a link that demonstrates this behaviour, or a code sample?

Comment 2

4 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.
Component: General → PDF Viewer
Product: Core → Firefox
(Reporter)

Comment 3

4 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

4 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'

Comment 5

4 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.
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.
Status: UNCONFIRMED → NEW
Ever confirmed: true

Updated

4 years ago
Whiteboard: [pdfjs-c-integration]
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

3 years ago
Any update on the resolution...I am facing this too..

Comment 9

3 years ago
Is anyone looking at this? Is there a workaround. Please note that the embedded frame is on the same domain.

Comment 10

3 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?

Comment 11

3 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.
Flags: needinfo?(bobbyholley)
(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.
Flags: needinfo?(bobbyholley)

Comment 13

3 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>.
Flags: needinfo?(bobbyholley)
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?
Depends on: 558184
Flags: needinfo?(bobbyholley)

Comment 15

3 years ago
Yes, that would definitely fix this bug.

Comment 16

3 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.

Comment 17

3 years ago
It is, but dupping forward to here, since this bug has more info.

Updated

3 years ago
Duplicate of this bug: 647658

Comment 19

3 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

Comment 20

3 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

3 years ago
Hi,

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

Thanks,
Shriom

Comment 22

3 years ago
Any fixes on this. ?
The bug to watch is bug 558184, which should get done (and possibly backported) this cycle.

Comment 24

2 years ago
Been a few months, anyone found a workaround?

Comment 25

2 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

Updated

2 years ago
Duplicate of this bug: 1202197

Comment 27

2 years ago
Disabling PDF.js doesn't work

Updated

2 years ago
Duplicate of this bug: 1232097

Comment 29

2 years ago
How come there is no proper solution for this after all these people reporting it.

Comment 30

2 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.

Comment 31

2 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.
Flags: needinfo?(bobbyholley)
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.
Flags: needinfo?(bobbyholley)

Comment 33

a year ago
I was able to get past this bug by updating my compatibility.js to latest version..

Comment 34

a year 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

11 months 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

11 months ago
@style-orate, this way you print the whole page not the iframe. So, it does not fix anything.

Comment 37

10 months 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

9 months ago
+1

Comment 39

7 months 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

4 months 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.

Comment 41

4 months 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

3 months ago
Any update on this? Our customer issues are rising to peak!!

Comment 43

3 months 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

3 months ago
#c35 will print whole page not specific iframe

Comment 45

3 months ago
Oops, you're write, my bad.

Comment 46

2 months ago
are we expect any date or its permanent bug in firefox which can not be resolved ?

Comment 47

2 months 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.
You need to log in before you can comment on or make changes to this bug.