Skip to content

Use Async functions and callbacks in background #389

Answered by aklinker1
michaelessiet asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, thanks for asking. Not sure what's going wrong without seeing your code, but here's an example extension that makes an network request in the background.

Note that the background's main function cannot be async, because you need to register all extension listeners synchronously when the service worker starts up. So to call an async API, like fetch, you have to use .then or a callback to handle the result.

wxt-async-background-example.zip

async-example.mp4

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@michaelessiet
Comment options

Answer selected by michaelessiet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants