webpack-contrib / worker-loader

A webpack loader that registers a script as a Web Worker
MIT License
1.46k stars 273 forks source link

Inline workers does not work in Edge Legacy anymore #292

Open mpk opened 4 years ago

mpk commented 4 years ago

Expected Behavior

Inline worker should execute in Edge Legacy

Actual Behavior

Inline worker does not execute in Edge Legacy

Code

// webpack.config.js
let HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: './index.js',
    plugins: [new HtmlWebpackPlugin()]
};
// index.js
import TestWorker from 'worker-loader?inline=no-fallback!./worker';

let worker = new TestWorker();
console.log(worker);
// worker.js
console.log('Log from worker');

How Do We Reproduce?

The code should write "Log from worker" into the console. However, it does not work in Edge Legacy browser (tested on version 18.18363). The worker is created successfully, but its contents are not executed, so nothing gets logged into the console.

I have looked at the worker-loader code and found out that the problem is in URL.revokeObjectURL(objectURL); line in inline.js. When I commented out that line, Edge executed the worker contents. Wrapping the call in setTimeout with 1000ms delay worked as well, but that solution seems quite hacky.

This issue is not present in worker-loader 2.0.0

elasim commented 3 years ago

I'm using 5.

alexander-akait commented 3 years ago

You need this loader only for inline? Because webpack 5 support worker out of box without this loader

elasim commented 3 years ago

Yes. This is the only loader can apply babel-loader for inline-worker as far as I know. By the way, I'm afraid bothering you because of this. If you are busy or it's annoying you, I'll handle this issue own myself.

alexander-akait commented 3 years ago

Honestly because webpack v5 supports workers out of box I think we need new loader, which covert module code to blob, so you can built-in new Worker('./file.js', import.meta.url) feature without this loader.

I think we need deprecate it in near future in favor new Worker('./file.js', import.meta.url), more abilities, more options, better support.