Merge pull request #13179 from ahocevar/blob-or-buffer

Use Buffer and data uri when Blob is not available
This commit is contained in:
Andreas Hocevar
2022-01-02 11:01:40 +01:00
committed by GitHub
2 changed files with 9 additions and 6 deletions
+6 -3
View File
@@ -151,9 +151,12 @@ function createWorker(config, onMessage) {
'});',
]);
const blob = new Blob(lines, {type: 'text/javascript'});
const source = URL.createObjectURL(blob);
const worker = new Worker(source);
const worker = new Worker(
typeof Blob === 'undefined'
? 'data:text/javascript;base64,' +
Buffer.from(lines.join('\n'), 'binary').toString('base64')
: URL.createObjectURL(new Blob(lines, {type: 'text/javascript'}))
);
worker.addEventListener('message', onMessage);
return worker;
}