undecaf / barcode-detector-polyfill

A WebAssembly polyfill for the Barcode Detection API
MIT License
112 stars 14 forks source link

Could this detector be used in the Web Worker context? #17

Closed paluh closed 2 months ago

paluh commented 2 months ago

Thanks a lot for putting this library together! Amazing stuff!

I have one question. It seems that this polyfill fails for me when I'm trying to use it from a Web Worker. On the other hand MSDN states (second NOTE there) that this interface should be accessible from Web Worker.

The method which fails is isImageBitmapSource which references types like HTMLImageElement and they are not present in the Web Worker global scope.

Could you please tell what do you think?

undecaf commented 2 months ago

Thanks @paluh for pointing this out!

Fixing it should not be hard, but could you please provide an example of where this occurs? I would like to add something like that to my tests.

paluh commented 2 months ago

Hi @undecaf, thanks for your quick response.

The problem which I mentioned is caused by this piece from isImageBitmapSource: https://github.com/undecaf/barcode-detector-polyfill/blob/master/src/BarcodeDetectorPolyfill.ts#L233. This private method is called from the detect so I'm not able to really use the class in my Web Worker (I hope I did not mess up anything ;-))

I can try to put together a PR this weekend as I will back hacking on the project and I have the code with Web Worker on a branch.

undecaf commented 2 months ago

Hi @paluh, I implemented what I think will fix the problem in release 0.9.21.

In JSDelivr, it may take some time until the latest release becomes the default download; so for now please specify the release number explicitly in the dependency URL, e.g. https://cdn.jsdelivr.net/npm/@undecaf/barcode-detector-polyfill@0.9.21

paluh commented 2 months ago

Thank you very much @undecaf! Works like a charm!

P.S. I feel a bit bad - I should provide the PR myself but I'm in the middle of my work week...

undecaf commented 2 months ago

@paluh No need to feel bad -- glad I could help!