New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: Permission denied to access property 'print' #10290
Comments
Similar to #5397, but it does not matter if you use an |
Same issue if using <object type="application/pdf"
data="/media/examples/In-CC0.pdf"
width="250"
height="200">
</object> |
Why open a duplicate issue here, when this is clearly already tracked in Bugzilla!? |
@Snuffleupagus Because the Firefox bug was reported 5 years ago and the root cause is pdf.js and not Firefox. No Firefox developer has touch this and I have bump into this issue multiple times and it can only be solved by changing pdf.js not Firefox. |
To clarify, the way pdf.js works is that the normal (15+ years) of printing a document, |
I might be wrong that the error is really how pdf.js is embedded into Firefox. But I assume that pdf.js could more easily listen for |
window.onbeforeprint = function() {
console.log('This will be called before the user prints.');
};
window.onafterprint = function() {
console.log('This will be called after the user prints');
}; Should work since Firefox 6 |
|
This is a duplicate of #5397 -- the root cause of the problem is that pdf.js is embedded into a document with a "resource://pdf.js" security principal. It's different from the embedding principal, so the same-origin policy blocks access to print and other properties. It doesn't matter if it's embedded in an iframe or an object. |
@Snuffleupagus is the web folder part of the pdf.js bundle that's embedded in Firefox? |
The main issue with #5397 is that it's half about printing when using pdf.js and half about how to print a document in Firefox when pdf.js is rendering the document, as in this ticket. @automatedbugreportingfacility you're right but I felt this requires a fresh issue since #5397 is mudding the waters. |
Changing the URI should happen in https://bugzilla.mozilla.org/show_bug.cgi?id=911444#c53 but in lieu of a fix in Firefox (haven't happen in 5 years), a work around would be to listen for the |
Can you clarify? For the A potential workaround on the pdf.js side would be to implement an |
@automatedbugreportingfacility uf, no that is not desirable at all. The perfect solution would be to have DOM API parity with all other browsers, where you can use I didn't create this issue because I use pdf.js but because Firefox uses pdf.js and I will be happy if this gets fixed in Firefox and not pdf.js or the other way around - either way I'll be happy 😃 |
I already state in #10290 (comment) that it's not relevant to this repository, and #10290 (comment) outlines (in some detail) why that is. Again, please note that it's not necessary/desirable to have duplicate issues open. |
In order to even touch |
@Snuffleupagus and @automatedbugreportingfacility just to be sure I understand what you are saying. There is no way to create a work-around Firefox security policy in pdf.js, when Is the above correct? |
Yes, you can't punch a hole in the browser's security mechanisms. Embedding pdf.js in a semi-privileged document was a big mistake in the first place, but there's no going back, and Mozilla sadly prefers spending money on ephemeral things like "Project Mortar". But I digress. |
Well at least Motar is discontinued. This issue could definitely be closed but before I (you) do, since I got 2 pdf.js experts here, I have two questions that possibly could help https://bugzilla.mozilla.org/show_bug.cgi?id=911444 along in the right direction.
|
@automatedbugreportingfacility Why is this decision irreversible? Couldn't you just create a new blank document with pdf.js and the same origin as the parent window and feed the PDF file to pdf.js? <iframe id="pdf" src="some-same-origin.pdf"></iframe>
<script>
document.getElementById('pdf').print()
</script> Bonus points, if pdf.js listen for |
I imagine, if pdf.js was embedded as a regular document, you would able to listen to the parent window. window.opener.addEventListener('beforeprint', event => {
event.preventDefault()
window.print() // pdf.js overrides the native print function already
}) Or change pdf.js to: let print = (window.opener || window).print;
window.print = function print() {
if (activeService) {
console.warn('Ignored window.print() because of a pending print job.');
return;
}
... On second thought, this would mean that pdf.js would swallow prints from the parent which is not what we want. |
Actually pdf.js is already doing the right thing. We just need firefox to dispatch |
Excerpt from pdf_print_service.js (found on https://mozilla.github.io/pdf.js/web/viewer.html): let print = window.print;
window.print = function print() {
if (activeService) {
console.warn('Ignored window.print() because of a pending print job.');
return;
}
ensureOverlay().then(function() {
if (activeService) {
overlayManager.open('printServiceOverlay');
}
});
try {
dispatchEvent('beforeprint');
} finally {
if (!activeService) {
console.error('Expected print service to be initialized.');
ensureOverlay().then(function() {
if (overlayManager.active === 'printServiceOverlay') {
overlayManager.close('printServiceOverlay');
}
});
return; // eslint-disable-line no-unsafe-finally
}
let activeServiceOnEntry = activeService;
activeService.renderPages().then(function() {
return activeServiceOnEntry.performPrint();
}).catch(function() {
// Ignore any error messages.
}).then(function() {
// aborts acts on the "active" print request, so we need to check
// whether the print request (activeServiceOnEntry) is still active.
// Without the check, an unrelated print request (created after aborting
// this print request while the pages were being generated) would be
// aborted.
if (activeServiceOnEntry.active) {
abort();
}
});
}
};
function dispatchEvent(eventType) {
let event = document.createEvent('CustomEvent');
event.initCustomEvent(eventType, false, false, 'custom');
window.dispatchEvent(event);
}
function abort() {
if (activeService) {
activeService.destroy();
dispatchEvent('afterprint');
}
} |
@Ugoku and @jtraulle Please vote on https://bugzilla.mozilla.org/show_bug.cgi?id=911444 to get it on the radar for Firefox developers. |
Thanks @dotnetCarpenter, I have voted on Bugzilla 🐞 |
Had the same issue using firefox. Solved it including the pdf into an iframe like this (the key is the way the pdf is linked): `$(".div_class").html('<iframe id="frame_id"></iframe>'); function printWhenReady(){ |
Why was this re-opened, when it's been stated repeatedly that it's a duplicate of https://bugzilla.mozilla.org/show_bug.cgi?id=911444 and not something that can be fixed in this repository!? @timvandermeij Can you please close this issue? |
I reopened it so that it is visible to the thousands of web developers that
eventually run into this issue. It makes it easy to spot and guide people
to the bugzilla issue. I thought it was better than keep getting duplicates
but I regress.
…On Tue, Jan 8, 2019 at 11:21 PM Tim van der Meij ***@***.***> wrote:
Closed #10290 <#10290>.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#10290 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AACq8wR4vNFtCtaUI-VRshKnQyDCQoZVks5vBRoGgaJpZM4Yv9So>
.
|
no, still |
@shmilyoo Please how did you get the path to PDFjs ?? |
The problem is the viewer. The embedded viewer causes the cross-origin problem. Try creating your own viewer. That will solve the problem. e.g. from here: https://pspdfkit.com/blog/2019/implement-pdf-viewer-pdf-js/ Or if you need a full featured viewer, you can use the Mozilla one from here: http://mozilla.github.io/pdf.js/web/viewer.html (for this one you will need to download the latest pdf.js and pdf.worker.js implementation). I just did that for a project at work, and it works like a charm. |
@vaspervnp If I may ask, were you able to programmatically call the print function ? |
@vaspervnp The irony is that, that is the exact same Mozilla viewer embedded in Firefox! We really need someone to change how pdf.js is embedded in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=911444#c58 |
Yes, I was. |
@vaspervnp it will be nice if you could provide a little code snippet on how you did that. |
@didagu |
Do you need special privileges to vote on bugzilla? I don't see that option anywhere. |
@mdodge-ecgrow looks like bugzilla removed the voting feature when they made the re-design. I'm not sure how we´re suppose to get firefox developers attention now... |
@dotnetCarpenter the icing on the cake is that, over a year ago, one of the developers complained that all of the +1 comments make it harder to see the technical discussion and therefore harder to resolve the bug. As if that's why it's been open for over 6 years and counting. Without the voting system, such comments are now the ONLY way to call attention to an issue, so I see no alternative. |
Stumbled upon this bug because that issue still persists to this day. You have to use Unfortunately it's one of those things that means I can't use Firefox in my workplace. If I can't use Firefox, there's no testing for Firefox, because why waste time and money when we only target Chrome (because that's where it works). So even if this issue is fixed eventually, my company will probably not ever switch back to Firefox, because "It works in Chrome". This issue is both regression and parity issue, and it was not fixed for 6 years now. Firefox keeps loosing market share and they wonder why. |
@swistak The good news is that this bug was fixed 1 month ago and will be in the next stable version of Firefox! Firefox 87 should be release on 2021-03-23 - in just 13 days. You can download Firefox Developer Edition and begin testing at your work place now. |
Configuration:
Steps to reproduce the problem:
What is the expected behaviour?
That the PDF can print as in every other browser than Firefox
What went wrong?
Error: Permission denied to access property 'print'
Please fix this as the go to universal print solution of PDF in browser has been broken for 5 years in Firefox since pdf.js was included in Firefox.
The web developer community has hundreds of bad solutions to this, because of a single project, pdf.js.
The text was updated successfully, but these errors were encountered: