skip to Main Content

I’m creating an SPA in Vue3 that requires a WebSocket to be open at all times to access database variables to the Client. I was wondering, maybe I could hide a WebSocket connection inside an invisible tab so that it’s always open, and if the user is idle for 30 minutes+, or if they close the site, it’ll disconnect and close the tab.

I’m not sure if this is feasible or not. I looked into Shared Workers, but it looks like not all browsers support it.

I was going to add. Sometimes users may manually type in the URL bar, www.blah.com/chatroom/123, to redirect to it. That would kill the original websocket connection and all the data that was stored to it would be lost. Maybe having an invisible tab would mitigate that.

Maybe StackOverFlow has a better suggestion?

2

Answers


  1. As far as i understood, you can also create the websocket from client’s javascript to the server.
    When your client loads, you can write the websocket code in startup js file.

    If this is not the case, could you please elaborate the situation.

    Login or Signup to reply.
  2. I am not sure if it’s possible to create hidden tab in a browser as the WebAPI will not provide such kind of functionality in my opinion.

    But I believe you can solve your problem with creating an <iframe> tag and it can have 0px width and height which will simulate as hidden tab and you can write your logic inside of the iframe. After it you can simply trigger an event which will listen your main webpage and do whatever you want.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search