Not Getting Alert from Running Full APIs without viewer sample

Product: Web Viewer

Product Version: 7.3.3

Please give a brief summary of your issue:
Followed steps provided in the Running Full APIs without viewer sample, but I’m receiving multiple error message and not receiving an alert.

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)
I simply followed your steps and received the following errors:
CoreControls.js:544 [Deprecation] SharedArrayBuffer will require cross-origin isolation as of M92, around July 2021. See SharedArrayBuffer updates in Android Chrome 88 and Desktop Chrome 92 - Chrome Developers for more details.
f @ CoreControls.js:544
iframe.html:1 Access to script at ‘file:someServer/c$/users/user/Desktop/ViewerPOC/WebViewer/lib/core/pdf/WasmThread.js’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
WebViewer/lib/core/pdf/WasmThread.js:1 Failed to load resource: net::ERR_FAILED
CoreControls.js:499 Uncaught DOMException: Blocked a frame with origin “null” from accessing a cross-origin frame.
at HTMLIFrameElement.r.onload (file://someServer/c$/users/user/Desktop/ViewerPOC/WebViewer/lib/core/CoreControls.js:499:494)
CoreControls.js:499 Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘null’) does not match the recipient window’s origin (‘null’).

Please provide a link to a minimal sample where the issue is reproducible:
SampleTest.html

<head>
  <script src="WebViewer/lib/core/CoreControls.js"></script>
  <script src="WebViewer/samples/FileSaver.min.js"></script>
  <script src="WebViewer/lib/core/pdf/PDFNet.js"></script>
  <script src="WebViewer/samples/full-apis/Setup.js"></script>
</head>
<body>
  <script src="SampleTest.js"></script>
</body>

SampleTest.js

(async function() {
  "use strict";
  const licenseKey = 'Insert commercial license key here after purchase';

  // the path to where the PDF worker files are
  CoreControls.setWorkerPath('WebViewer/lib/core');


	async function main() {
	  try {
		// creates an empty pdf document
		const doc = await PDFNet.PDFDoc.createFromURL("Sample.pdf");    
		doc.initSecurityHandler();
		// Locks all operations on the document
		doc.lock();

		// insert user code after this point
		const pgnum = await doc.getPageCount();
		alert(`Test Complete! Your file has ${pgnum} pages`);
	  } catch(err) {
		console.log(err.stack)
	  }
	}

  await PDFNet.runWithCleanup(main, licenseKey);
  // Alt: PDFNet.runWithoutCleanup(main, licenseKey);
  // 'runWithoutCleanup' does not deallocate anything after finishing.
})();

Hi James,

I just followed the step in the sample you are referring to https://www.pdftron.com/documentation/web/guides/full-api/running-without-viewer/ and I had no issues. Seeing that error readout it seems like you are hosting the webviewer package on a different origin. For this project to work the webviewer package must exist on the same origin as your SampleTest.html file or you will continue to get CORS errors. If this does not resolve your issue, could you share your project directory, and could you also share how you are running the project?

If it is important to load the WebViewer from another domain you can follow this guide: https://www.pdftron.com/documentation/web/guides/wv-inside/#loading-webviewer-from-another-domain and you can see that implemented in this sample project GitHub - PDFTron/webviewer-cors: Load WebViewer's lib on a different domain

Best Regards,
Dustin Riley
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

Hi Dustin,

Here’s the


directory.

I am opening the SampleTest.html file in Chrome to run the project.

It feels like I’m probably missing some steps, but I haven’t seen any in the sample project instructions.

Hi James,

To run the project, you’ll just need to have this folder hosted on a static local server, and just about anyone will do.

An easy way to do it if you don’t have anything set up is the HTTP-server npm package. From the command line, run npm install -g http-server and once that’s installed, navigate to where you have that SampleTest.html located and run http-server.

Now go to http://localhost:8080 and if everything was successful, the full API should have run, and you won’t be getting any more errors.

Cheers,
Dustin