{"action":"created","issue":{"url":"https://api.github.com/repos/mozilla/pdf.js/issues/5397","labels_url":"https://api.github.com/repos/mozilla/pdf.js/issues/5397/labels{/name}","comments_url":"https://api.github.com/repos/mozilla/pdf.js/issues/5397/comments","events_url":"https://api.github.com/repos/mozilla/pdf.js/issues/5397/events","html_url":"https://github.com/mozilla/pdf.js/issues/5397","id":45547136,"number":5397,"title":"Unable to Print PDF when loaded in iFrame","user":{"login":"Petce","id":2841469,"avatar_url":"https://avatars.githubusercontent.com/u/2841469?v=3","gravatar_id":"","url":"https://api.github.com/users/Petce","html_url":"https://github.com/Petce","followers_url":"https://api.github.com/users/Petce/followers","following_url":"https://api.github.com/users/Petce/following{/other_user}","gists_url":"https://api.github.com/users/Petce/gists{/gist_id}","starred_url":"https://api.github.com/users/Petce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Petce/subscriptions","organizations_url":"https://api.github.com/users/Petce/orgs","repos_url":"https://api.github.com/users/Petce/repos","events_url":"https://api.github.com/users/Petce/events{/privacy}","received_events_url":"https://api.github.com/users/Petce/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mozilla/pdf.js/labels/3-upstream","name":"3-upstream","color":"e102d8"},{"url":"https://api.github.com/repos/mozilla/pdf.js/labels/4-printing","name":"4-printing","color":"DDDDDD"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-10-11T09:49:27Z","updated_at":"2015-05-08T21:23:18Z","closed_at":null,"body":"I am attempting to use Javascript to focus and print a PDF file that is loaded within a iframe I dynamically placed into the DOM. This issue is specifically occurring for me in Firefox.\r\n\r\nMy code resembles the following:\r\n\r\n```html\r\n<iframe name=\"printer_frame\" id=\"printer_frame\" src=\"http://domain.com/media/eparcel_label_1413020567.pdf\"></iframe>\r\n```\r\n\r\n```javascript\r\nwindow.frames['printer_frame'].window.focus();\r\nwindow.frames['printer_frame'].window.print();\r\n```\r\n\r\nI receive the following error:\r\n>Error: Permission denied to access property 'print'\r\n\r\nMy research is telling me that this should work, further reading has lead me to believe that this may be a bug. Any help would be appreciated.\r\n\r\n###### Edit\r\nI tested the functionality by replacing the PDF file with a screen shot in PNG format of the first page within it and the print functionality worked.\r\n\r\n###### Edit\r\nFurther testing. Added pdfjs to my chrome install, and attempted to print with the same code above. same error:\r\n>SecurityError: Blocked a frame with origin \"http://domain.com\" from accessing a cross-origin frame.\r\n\r\n```javascript\r\ncode: 18\r\nmessage: \"Blocked a frame with origin \"http://domain.com\" from accessing a cross-origin frame.\"\r\nname: \"SecurityError\"\r\nstack:\r\n\"Error: Blocked a frame with origin \"http://domain.com\" from accessing a cross-origin frame.\r\n    at Error (native)\r\n    at <anonymous>:2:34\r\n    at Object.InjectedScript._evaluateOn (<anonymous>:730:39)\r\n    at Object.InjectedScript._evaluateAndWrap (<anonymous>:669:52)\r\n    at Object.InjectedScript.evaluate (<anonymous>:581:21)\"\r\n```\r\n\r\nI should make it clear that the PDF file is being loaded on the same domain."},"comment":{"url":"https://api.github.com/repos/mozilla/pdf.js/issues/comments/100372486","html_url":"https://github.com/mozilla/pdf.js/issues/5397#issuecomment-100372486","issue_url":"https://api.github.com/repos/mozilla/pdf.js/issues/5397","id":100372486,"user":{"login":"dahjelle","id":156557,"avatar_url":"https://avatars.githubusercontent.com/u/156557?v=3","gravatar_id":"","url":"https://api.github.com/users/dahjelle","html_url":"https://github.com/dahjelle","followers_url":"https://api.github.com/users/dahjelle/followers","following_url":"https://api.github.com/users/dahjelle/following{/other_user}","gists_url":"https://api.github.com/users/dahjelle/gists{/gist_id}","starred_url":"https://api.github.com/users/dahjelle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dahjelle/subscriptions","organizations_url":"https://api.github.com/users/dahjelle/orgs","repos_url":"https://api.github.com/users/dahjelle/repos","events_url":"https://api.github.com/users/dahjelle/events{/privacy}","received_events_url":"https://api.github.com/users/dahjelle/received_events","type":"User","site_admin":false},"created_at":"2015-05-08T21:23:18Z","updated_at":"2015-05-08T21:23:18Z","body":"I think I know the reason for this, at least in Firefox. In a simple example such as the above, if you use the Firefox DevTools to examine `document.domain` in both the main page and in the iframe, I found that `document.domain` is `pdf.js` for the PDF.js renderer—so the browser's cross-origin restrictions are kicking in.\r\n\r\nAdditionally, if I built PDF.js from source, and set my iframe to `web/viewer.html?file=`, then calling telling the iframe to print (as in the OP), it worked fine.\r\n\r\nIs there a way for PDF.js (at least when running in Firefox) to accept messages from other windows, perhaps via something like `window.postMessage`? (I've never used it, so I don't know if it is appropriate for this use-case or not.)"}}