You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m currently working on a Chrome extension using the Plasmo framework, and I’ve encountered an issue with waiting for the background worker to initialize before my script starts. My code, which is built with Alpine.js, calls the background worker via relay as soon as the script starts. However, it seems like the background worker hasn’t initialized yet, causing my code to wait indefinitely. Example code:
import{sendToBackgroundViaRelay}from"@plasmohq/messaging";exportdefault()=>({version: null,asyncinit(){console.log('alpine component init')letresult=awaitsendToBackgroundViaRelay({name: "version"})//this will never be called, it just hang thereconsole.log('get version completed')}})
console output
🔵 INFO | [plasmo/parcel-runtime]: Connected to HMR server for [redacted]/main-world.ts
ext-alert.js:7 alpine component init
admin.71825fa5.js:151 🔵 INFO | [plasmo/parcel-runtime]: Connected to HMR server for [redacted]/background.ts
If I use setTimeout to delay the call by a few seconds, the code works normally. However, this isn’t a reliable solution as the initialization time can vary.
How can I properly check if the background worker has been initialized before making the call?
Any help or suggestions would be greatly appreciated!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi everyone,
I’m currently working on a Chrome extension using the Plasmo framework, and I’ve encountered an issue with waiting for the background worker to initialize before my script starts. My code, which is built with Alpine.js, calls the background worker via relay as soon as the script starts. However, it seems like the background worker hasn’t initialized yet, causing my code to wait indefinitely.
Example code:
console output
If I use setTimeout to delay the call by a few seconds, the code works normally. However, this isn’t a reliable solution as the initialization time can vary.
How can I properly check if the background worker has been initialized before making the call?
Any help or suggestions would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions