Is EventSource available in Retool's "Run JS Code" Resource?

As the title says, I'm wondering if there is a way to use an EventSource instance (EventSource - Web APIs | MDN) in Retool's Javascript resource.

I saw in an old post from 2020 a user was citing code that uses EventSource directly in retool (Process Incoming Webhooks for Retool). However, when I tried to use it myself in the JS resource it tells me that " 'EventSource' is not defined".

Is there any way I can add/enable EventSource?

Thanks

Hey @Abderrahman_Sobh! Doing some testing it looks as though Retool does support the EventSource API, would you mind sending over a screenshot of the code you're trying to call it in for context?

1 Like

Sure, I'm just trying to instantiate a new object and it says that EventSource is undefined. Here is a screenshot:

I'm seeing the same thing though it looks like it may only be a linting error, the following is from a test app that listens to events from a localhost server and seems to work fine:

Based on the EventSource docs though it looks like the API might not support passing Authorization headers. I'm not very familiar with it and could easily be wrong, but do wonder if that might be causing issues here.
server_sent_events.json

Hi @Abderrahman_Sobh, curious if you ended up getting this to work?

Hi @Jakob_Zacherl,

Can you share more about your use case? Are you also looking to pass in auth headers? :thinking: As far as I can tell, adding headers isn't supported, but I'm curious if you have this implemented somewhere outside of Retool

Hi @Tess !
I am looking into possible ways to build an app that has some realtime components (notification centre).

Got it! I haven't tested EventSource in a custom component, but in general, for realtime uses cases, I recommend trying a custom React component (see similar suggestion here).