kweb-core
kweb-core copied to clipboard
Use polling or an alternate mechanism if websockets is unavailable
When I visit a page that uses Kweb, my browser will immediately go into a refresh loop. The problem is probably caused by a Firefox setting or by one of the Firefox plugins listed below, but I'm not able to reproduce it yet in a new Firefox profile.
This happens for http://demo.kweb.io:7659/ but also in the most basic Kweb applications that only output some string. So the JavaScript code that Kweb injects in pages, is somehow causing a refresh loop.
The Firefox console shows:
Navigated to http://localhost:8080/
<empty string> localhost:8080:16:13
Evaluated [document.origin] undefined localhost:8080:50:21
Queueing WebSocket message as connection isn't established {"id":"oXkR5d","callback":{"callbackId":446825956}} localhost:8080:172:17
Establishing websocket connection ws://localhost:8080/ws localhost:8080:117:13
Firefox can’t establish a connection to the server at ws://localhost:8080/ws. localhost:8080:118:13
WebSocket error
error { target: WebSocket, isTrusted: true, srcElement: WebSocket, currentTarget: WebSocket, eventPhase: 2, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, … }
localhost:8080:159:21
Forcing page reload localhost:8080:161:21
Socket closed localhost:8080:140:21
WebSocket was closed without a reason specified
close { target: WebSocket, isTrusted: true, wasClean: false, code: 1006, reason: "", srcElement: WebSocket, currentTarget: WebSocket, eventPhase: 2, bubbles: false, cancelable: false, … }
localhost:8080:148:21
onclose http://localhost:8080/:148
(Async: EventHandlerNonNull)
connectWs http://localhost:8080/:139
buildPage http://localhost:8080/:326
onload http://localhost:8080/:1
Forcing page reload localhost:8080:154:25
Navigated to http://localhost:8080/
Which is then repeated on every automatic refresh.
I could try to work around this problem at the client side, but IMO the injected JavaScript code shouldn't perform a forced refresh at all, but instead give a warning message.
My System:
- Latest Firefox version
- HTTPS Everywhere (plugin)
- NoScript (plugin)
- Privacy Badger (plugin)
- Privacy Settings (plugin)
- uBlock Origin (plugin)
Hmm, it looks like its unable to establish the websocket connection - could you try temporarily disabling HTTPS Everywhere? That seems like the most likely culprit.
It seems that I disabled websockets some months ago in Firefox, because some websites abuse websockets by performing portscans at localhost. https://nullsweep.com/why-is-this-website-port-scanning-me/
Btw, it would maybe also be interesting to have a fallback mechanism using polling or Server Push, in case clients have websockets disabled or if a CDN blocks it.
Interesting, do you find that disabling websockets breaks a lot of websites, or do they all just fall back to something else?
If this is a common problem then we should definitely have a fallback mechanism, I'll update this issue to be a feature request.
Sometimes I do get websites that don't fully work, then I try Firefox private mode or a different Firefox profile, or switch temporarily to Chrome. But this doesn't happen often, and it can be difficult to diagnose because of the many blocking Firefox plugins that I use. But now that I know that disabling websockets can cause some unexpected problems, I'll keep an eye on it. But I haven't seen websites (or web frameworks) using websockets for common DOM event use cases before, only for things like interactive chats, but I didn't really looked at websockets when analyzing websites. But Youtube live videos (with live chats), or Twitter doesn't seem to use websockets, but polling, if I'm correct, even though websockets would maybe be more efficient.
Yeah, just looking at Facebook it does maintain a websocket connection, but as you say it seems to be primarily related to the chat functionality.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Still relevant.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.