You need a proper bot really.
Also followers don’t really like to be welcomed in chat especially lurkers. But do what works for the stream
You need implicit auth, since you need chat write powers/ability to login to chat to send the thanks for follow message
Example:
I really wouldn’t do it like this. But it can be made to work like this.
Server side using webhooks for follow notification and repeat follow de-duplication and a long running bot would fit better.
A lot of stuff like this is disabled in the browser source, since it’s essentially a headless browser and “workarounds”/alternative access is needed