Use Buffer and data uri when Blob is not available

This commit is contained in:
Andreas Hocevar
2022-01-01 22:15:12 +01:00
parent bc2969fd78
commit 00b7bc60ac
2 changed files with 9 additions and 6 deletions

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;
}