Getting error when trying to access document on same domain

2843 views
Skip to first unread message

Peter Znameroski

unread,
Oct 22, 2013, 8:04:45 PM10/22/13
to pdfnet-w...@googlegroups.com
I am working on a javascript web app that displays a PDF in an HTML5 iframe but when I run the app I get this error in the javascript console output:

Uncaught SecurityError: Blocked a frame with origin "http://localhost:8080" from accessing a frame with origin "http://localhost:8080". The frame requesting access set "document.domain" to "localhost", but the frame being accessed did not. Both must set "document.domain" to the same value to allow access.

This error seems to occur in the WebViewer.js in the _createHTML5 function. The PDF document is located on the same domain that it will be displayed on. When I run the app at host "[myIPAddress]:8080" it seems to work.

Please let me know if I can provide more information.

Thanks,
Peter

Matt Parizeau

unread,
Oct 23, 2013, 1:26:53 PM10/23/13
to pdfnet-w...@googlegroups.com
Hi Peter,

What browser(s) are you seeing the error in and what server are you using?

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Peter Znameroski

unread,
Oct 23, 2013, 2:20:40 PM10/23/13
to pdfnet-w...@googlegroups.com
I am seeing this in Chrome. I did not see it in Firefox but when stepping through the code, the place where the error occurred in Chrome was skipped over. The server I am using is a local Tomcat 7.0 instance.

-Peter

Peter Znameroski

unread,
Oct 23, 2013, 3:19:00 PM10/23/13
to pdfnet-w...@googlegroups.com
I also see it on Safari with an additional error with the message: 

TypeError: 'undefined' is not an object (evaluating 'me.instance.docViewer') WebViewer.js:225

This error occurs around the same line as the "Uncaught SecurityError" that occurred in Chrome.

-Peeter

Peter Znameroski

unread,
Oct 23, 2013, 9:12:30 PM10/23/13
to pdfnet-w...@googlegroups.com
I was able to work around the issue by adding:

<script>
   document.domain = "localhost";
</script>

to the body sections of DocViewer.html and ReaderControl.html but is there a more elegant solution?

-Peter

Matt Parizeau

unread,
Oct 24, 2013, 12:48:25 PM10/24/13
to pdfnet-w...@googlegroups.com
I just tried running WebViewer 1.6 on Tomcat 7.0.30 and wasn't able to reproduce the problem.  Which version of WebViewer are you using because I believe we removed DocViewer.html in 1.5.  You could try upgrading to the latest version but it's good you were able to find a workaround.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Peter Znameroski

unread,
Oct 24, 2013, 6:40:46 PM10/24/13
to pdfnet-w...@googlegroups.com
Ehh seems we are on version '1.3.3.16421' so maybe upgrading will have an effect. Thanks, Matt.

Thanks,
Peter

Alice Wu

unread,
Nov 11, 2013, 7:47:25 PM11/11/13
to pdfnet-w...@googlegroups.com
Hi Matt,

FYI, Peter and I are on the same team. We just upgraded to 1.6.0 and it did not fix this issue. 

Alice
Reply all
Reply to author
Forward
0 new messages