When loading KMZs, I get an error when trying to access a ThirdParty/Workers/inflate.js

I'm hosting my code in one place and accessing it from a different origin.

I get the following error when loading a KMZ.

“Uncaught DOMException: Failed to construct ‘Worker’: Script at ‘https://YYYYY.com/ThirdParty/Workers/inflate.js’ cannot be accessed from origin ‘https://ZZZZZZ.com’.”

This is because ThirdParty/zip.js tries to build a worker blindly using the domain that the code is sitting on. The worker code does exist at the target url, but the browser won't allow access to it.

if (obj.zip.useWebWorkers) {
			worker = new Worker(obj.zip.workerScriptsPath + INFLATE_JS);
			launchWorkerProcess(worker, reader, writer, offset, size, oninflateappend, onprogress, oninflateend, onreaderror, onwriteerror);
		} else
			launchProcess(new obj.zip.Inflater(), reader, writer, offset, size, oninflateappend, onprogress, oninflateend, onreaderror, onwriteerror);
		return worker;

It looks like you should be able to set the `useWebWorkers` value on the zip instance, but there's no way to specify that from KmlDataSource.

Is there any way to get around creating these workers from a different domain? I know the other workers in cesium use the TaskProcessor factory to sidestep cors issues.

Can I somehow do this with the zip dependency?

I think this is the same issue referenced here https://cesiumjs.org/forum/#!topic/cesium-dev/mYpD1-fyjFs/discussion

Cesium Version 1.41.0
Chrome Version 63.0.3239.132

Hi Andrew,

zip.js is third party code we include in the Cesium library. The fix here may just be to modify that third party code in order to build the web worker url consistently with the rest of the Cesium library. However, it is just building a url relative to the cesium base location and loading that script.

If you could provide a code snippet with your use case, that would help track down what exactly we can do to work around this issue.

Thanks!

Gabby

Hi Gabby,
I came to this conclusion of modifying zip.js too after looking back through the commits and seeing that it’s already been modified to import buildModuleUrl to add the correct workerScriptsPath.
I’ve taken inspiration from the TaskProcessors’s getWorkerUrl for this.
I have prepared a small PR and will likely submit it today following the guidelines laid out in GitHub.
Thanks for your help,
Andew

Thanks, Andrew! I see your PR on github and we should get it reviewed shortly! Thanks for the contribution!