WebViewer Web Component breaks the instantiation of ESM web workers on the page

WebViewer Version: 11.5.0

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?
No

Is your issue related to annotations?
No

Please give a brief summary of your issue:
Using the WebViewer Web Component breaks other web workers on the page that load as ESM modules. The issue is not present when using the IFrame.

Please describe your issue and provide steps to reproduce it:

After loading the WebViewer web component, trying to instantiate an ESM web worker that uses the import statement fails with the error Cannot use import statement outside a module. The ESM web worker is instantiated like this:

new Worker(
  new URL('./worker.js', import.meta.url),
  {
    type: 'module',
  }
)

Note that the worker constructor takes two parameters.

Instantiating the Worker before creating the WebViewer works without error.

It looks like the webviewer-core.min.js script patches the Worker constructor as follows (I’ve done my best to make sense of the minified/obfuscated code)

var originalWorker = window.Worker
window.Worker.KEa || (window.Worker = function(workerParam) {
  worker = new originalWorker(workerParam);
  ka.push(worker);
  return worker
}

Note that the new Worker constructor only takes one argument, and so the second argument (which contains the type: 'module' code) is lost, and the worker loads as a classic worker. I modified the code locally to use a spread operator, and the ESM worker starts loading correctly.

var originalWorker = window.Worker
window.Worker.KEa || (window.Worker = function(...workerParams) {
  worker = new originalWorker(...workerParams);
  ka.push(worker);
  return worker
}

Please provide a link to a minimal sample where the issue is reproducible:
Can create on request

1 Like

Hello, I’m AiRon, an automated tech support bot :robot:
While you wait for one of our customer support representatives, I can help you with your question.


It seems like you’re experiencing an issue where the WebViewer Web Component modifies the Worker constructor, which interferes with the instantiation of ESM web workers. This problem arises because the patched Worker constructor does not accommodate the second parameter, which specifies the type of the worker as a module.

Some things you can try:

  • Ensure that the WebViewer Web Component does not interfere with global objects by checking any scripts or settings that might override or modify window.Worker.

  • Modify the WebViewer’s core script to accommodate multiple parameters in the Worker constructor, similar to your temporary fix using the spread operator.

  • Consider using the WebViewer as an IFrame if modifying the Web Component is not feasible, as this setup does not seem to affect ESM web workers.

  • Report this behavior to Apryse support as it might require an internal fix or update to the WebViewer Web Component script.



Here are some resources that might help you:


Hopefully, this helps you solve your problem while you wait for a human to get back to you.

1 Like

Hello Luke,

Thank you contacting us. Unfortunately, web component overrides the global window and that is what’s most likely causing the issue here.

Could you provide a minimal sample project to reproduce the issue? This project should contain the bare minimum code needed to reproduce the issue. You can provide a download link or a GitHub repo.

Best Regards,
Darian

1 Like

The issue can be replicated using this repo GitHub - luke-stead-sonocent/apryse-web-component-worker-repro

Instructions and replication steps can be found in the readme

1 Like

Hello Luke,

Thank you for the sample project, I was able to reproduce the issue with web component. I have submitted a report about this issue to the product team.

Best Regards,
Darian

2 Likes