Unsure how to use postMessage when WebViewer source on other domain

WebViewer Version:
Latest

Do you have an issue with a specific file(s)?
No

Can you reproduce using one of our samples or online demos?
No

Are you using the WebViewer server?
No

Does the issue only happen on certain browsers?
No

Is your issue related to a front-end framework?
Yes

Is your issue related to annotations?
No

Please give a brief summary of your issue:
Viewer is on a different domain, the promise from WebViewer function is rejected

Please describe your issue and provide steps to reproduce it:
Hi there, I’d like some help with this issue please. I am trying to test the PDFJSExpress Viewer. I need to load the WebViewer library files from a different domain to the one where I instantiate the WebViewer. I’ve tried following this guide but I still can’t get it to work. My script is super simple:

WebViewer({
    path: 'http://myotherdomain.com/PDFJSExpress-view-only/lib',
    licenseKey: 'mykey',
    initialDoc: 'https://pdftron.s3.amazonaws.com/downloads/pl/webviewer-demo.pdf',
}, document.getElementById('viewer'))
.then(instance => {
    console.log("Got instance.")
});

However, even with this simple code I get the following error in my console:

pdf.html:1 Uncaught (in promise) Viewer is on a different domain, the promise from WebViewer function is rejected and API functions will not work because of cross domain permissions. See https://www.pdftron.com/kb_cross_origin for more information.

And the console.log line does not execute. How am I supposed to instantiate a WebViewer instance and use the postMessage API if it errors out and won’t even print a logging statement? Also, the pdf does actually render on the page. Any assistance would be great ty.

Please provide a link to a minimal sample where the issue is reproducible:
Not sure

1 Like

Hello Harsturomai,

Can you send a screenshot of the network console?
It could be that the files are not being found on the set path

Best regards,
Tyler

1 Like