wKovacs64 / hibp

An unofficial TypeScript SDK for the 'Have I been pwned?' service.
https://wkovacs64.github.io/hibp
MIT License
115 stars 5 forks source link

Errors in web workers or extension background threads #456

Closed ArcadeRenegade closed 7 months ago

ArcadeRenegade commented 7 months ago

Looks like all API methods fail when trying to call them from a web worker or extension background threads since window is undefined.

Looking at src/api/web-fetch.ts it looks like it assumes it is running in a NodeJS environment if window is undefined.

Perhaps a more accurate check to see if native fetch is available can be simply 'fetch' in globalThis

wKovacs64 commented 7 months ago

Sounds reasonable. PRs welcome 🙂 or I'll get to it when I can.

wKovacs64 commented 7 months ago

@ArcadeRenegade Can you try hibp@experimental and see if it resolves your issue? 🙏

wKovacs64 commented 7 months ago

@ArcadeRenegade Can you try hibp@experimental and see if it resolves your issue? 🙏

I think the one I published when I wrote that was busted, you may need to force reinstall the experimental tag if you were quick to test it (or install hibp@0.0.0-dev.d74e2ad2 directly). 😛

ArcadeRenegade commented 7 months ago

@wKovacs64 I just tested and I can confirm it works in an extension background thread / web worker.

ArcadeRenegade commented 7 months ago

@wKovacs64 thanks for looking into this!

wKovacs64 commented 7 months ago

Sweet, thanks for confirming!

wKovacs64 commented 7 months ago

@all-contributors please add @ArcadeRenegade for bug reports.

allcontributors[bot] commented 7 months ago

@wKovacs64

I've put up a pull request to add @ArcadeRenegade! :tada:

wKovacs64 commented 7 months ago

@ArcadeRenegade Fix has been released in v14.1.0. Thanks again.