Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

chore: added worker support #163

Merged
merged 11 commits into from
May 30, 2023
Merged

chore: added worker support #163

merged 11 commits into from
May 30, 2023

Conversation

lquixada
Copy link
Owner

@lquixada lquixada commented May 6, 2023

This work enables cross-fetch to work in workers environment such as Service Workers and Cloudflare Workers.

This PR addresses issues #69, #78 and #142.

@lquixada lquixada changed the title chore: adds worker support chore: added worker support May 6, 2023
@ThisIsMissEm
Copy link

Ah cool, in the meantime, Inrupt shipped their own fetch library which uses native feature if available: https://npm.im/@inrupt/universal-fetch

Which doesn't do polyfilling for browsers, given the wide support for fetch these days

@lquixada lquixada merged commit 0604d63 into main May 30, 2023
@lquixada lquixada deleted the worker-support branch May 30, 2023 15:23
@spencercap
Copy link

@lquixada 👏 THANK YOU !
in which version of cross-fetch is workers support live?

@lquixada
Copy link
Owner Author

lquixada commented Jun 3, 2023

@spencercap it'll be on version 4. you can test it using npm install cross-fetch@latest-v4.x. please let me know if you find any issues.

@spencercap
Copy link

@lquixada it works! thanks so much.

the only thing i needed to change in this library's fork to get it working was to remove the mode: "cors" arg as you can see in the 2nd commit of this PR: algorand/js-algorand-sdk#794

it seems to me that the CF worker's fetch api doesn't support this even though it is supposed to by a direct mirror of the standard fetch api... which makes me wonder if it should be cross-fetch's job to remove this arg IF in the workers env?

@lquixada
Copy link
Owner Author

lquixada commented Jun 9, 2023

@spencercap I'm glad that it worked out for you! Please note that cross-fetch purpose is to only act as proxy to different implementations depending on the environment. Eventual conflicts between implementations should be addressed by the libs (like node-fetch or whatwg-fetch), envs (like node or service-worker) or authors (like yourself).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants