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