kweb-core icon indicating copy to clipboard operation
kweb-core copied to clipboard

Use polling or an alternate mechanism if websockets is unavailable

Open devxzero opened this issue 4 years ago • 5 comments

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)

devxzero avatar Mar 16 '21 11:03 devxzero

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.

sanity avatar Mar 17 '21 15:03 sanity

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.

devxzero avatar Mar 17 '21 16:03 devxzero

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.

sanity avatar Mar 17 '21 17:03 sanity

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.

devxzero avatar Mar 17 '21 19:03 devxzero

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.

sanity avatar Mar 18 '21 15:03 sanity

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.

github-actions[bot] avatar Oct 10 '22 03:10 github-actions[bot]

Still relevant.

sanity avatar Oct 15 '22 19:10 sanity

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.

github-actions[bot] avatar Nov 15 '22 03:11 github-actions[bot]

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.

github-actions[bot] avatar Dec 16 '22 02:12 github-actions[bot]

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.

github-actions[bot] avatar Jan 16 '23 02:01 github-actions[bot]