Use an object url to fix cross-origin workers in Safari (see microsoft/monaco-editor#2110)

This commit is contained in:
Alex Dima 2020-09-18 22:41:42 +02:00
parent 50cb4feaf7
commit 08c92c9161
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0

View file

@ -38,8 +38,12 @@ export function getWorkerBootstrapUrl(scriptPath: string, label: string, forceDa
const myPath = 'vs/base/worker/defaultWorkerFactory.js';
const workerBaseUrl = require.toUrl(myPath).slice(0, -myPath.length);
const js = `/*${label}*/self.MonacoEnvironment={baseUrl: '${workerBaseUrl}'};importScripts('${scriptPath}');/*${label}*/`;
const url = `data:text/javascript;charset=utf-8,${encodeURIComponent(js)}`;
return url;
if (forceDataUri) {
const url = `data:text/javascript;charset=utf-8,${encodeURIComponent(js)}`;
return url;
}
const blob = new Blob([js], { type: 'application/javascript' });
return URL.createObjectURL(blob);
}
}
return scriptPath + '#' + label;