#Run async code in preload script

15 messages · Page 1 of 1 (latest)

dry cedar
#

I have very specific use case, where I need to create a global structure in renderer's window.
The structure contains initial values and is going to be modified later by renderer process (so context bridge is out of the way here, since it's read only). Those values I want to fetch from main process.

It's not possible to use top level await either (because of how Electron runs the preload)

My question is: Is there any way to await that code, to make sure all promises resolved before loading the site?

#

Please tag me if you respond 🙂

twin zodiac
#

@dry cedar why don't you just do that await stuff in the main process and not load the browser window until the await completes? Then you can pass whatever you need into the preload script?

dry cedar
twin zodiac
#

If you can give me more of a description of what you're trying to accomplish, I might be able to offer more specific details

dry cedar
#

the galaxyInitData is a thing I want to obtain from main process, parialy or as a whole

somber palm
#

Wait until your data is ready on renderer side

dry cedar
#

I can't modify renderer code

somber palm
#

i think ipc handle/invoke better for your usecase

#

thats bad

#

you can block preload with sendSync call

dry cedar
#

will try that

somber palm
#

with doing stuff in main process