Is it possible to use anvil without WebSockets?

What I’m trying to do:
I’m curious about why Anvil uses WebSocket by default and whether it’s possible to operate an Anvil app without WebSocket. Is there a way to disable WebSocket functionality in an Anvil app?

What I’ve tried and what’s not working:
We’re encountering an issue where some users are unable to access the our app, and we think they might be blocking WebSocket. If they are, changing that policy is out of our reach, so we want to know if we can change our app’s configuration to make it accessible to all.

Assistance Needed:
We’d need insights or guidance on how Anvil utilizes WebSocket, and if there are options to manage or disable it? Additionally, any advice on troubleshooting login issues related to WebSocket in Anvil apps would be greatly appreciated.

I don’t think Websockets might be creating any error. A couple of days ago, I was digging a bit deeper into the working of anvil websockets (while trying to implement an unrelated feature).

This is what I stumbled across

class AnvilWebSocket extends WebSocket {
    send(data: string | ArrayBufferLike | Blob | ArrayBufferView) {
        try {
            super.send(data);
        } catch (e) {
            if (firstSendFail) {
                throw new WebsocketFallback("use HTTP");
            }
            throw e;
        }
        firstSendFail = false;
    }
}

Based on my understanding, Anvil appears to fallback to HTTP if websocket fails. Although I have no idea if it actually works or not.

Someone from the Anvil team would have to confirm if it works or not.

Actually, I didn’t implement anything for the websocket in the Anvil but I am talking about the case when we start the anvil server it gives us the message like this:
Connecting to ws://localhost:3030/_/downlink
Anvil websocket open

Also, when I see in the application network’s WS tab then It is using websocket like this:

So it makes me curious to know that what is this use case and is there a chance to affect login or any related blockage for the users?

Anvil uses websockets by default for any call to the server. So yes, if websocket doesn’t work than any kind of communication with backend (including login) will be affected (unless Anvil does have a feature of HTTP as fallback which I have no idea about).

It will be really helpful if you can just tell what errors your users are exactly facing.

1 Like