fregante / GhostText

👻 Use your text editor to write in your browser. Everything you type in the editor will be instantly updated in the browser (and vice versa).
https://GhostText.fregante.com
MIT License
3.28k stars 117 forks source link

Opens multiple editor windows on subsequent clicks #114

Closed moritz closed 3 years ago

moritz commented 6 years ago

I'm using GhostText 17.10.25.1400 with Firefox 57 on Ubuntu 17.04 together with https://github.com/falstro/ghost-text-vim

When I first click on the GhostText icon, it opens one gvim window. When I save the text and close the editor, and then click on the GhostText icon a second time, it opens two gvim windows, one empty, one with the text from that text area that is in focus. Each time I repeat this, I get one more empty gvim window (so on the 5th run I get 4 empty and 1 normal gvim windows).

There is an issue in the vim plugin repo at falstro/ghost-text-vim#3 which claims this is a problem in GhostText, not in the vim plugin.

sukima commented 6 years ago

After writing my very own server code I can with absolute certainly confirm that GhostText does in fact spawn exponentially more editors on every click.

I've watched the traffic in WireShark and can confirm that on first click:

  1. GhostText sends a GET / to localhost:4001
  2. GhostText receives initial payload.
  3. GhostText initiates a WebSocket connection.

When the editor closes the WebSocket is closed and GhostText sends a user notification that it has disconnected.

On second click:

  1. GhostText sends a GET / to localhost:4001
  2. GhostText sends a GET / to localhost:4001
  3. GhostText receives initial payload.
  4. GhostText receives initial payload.
  5. GhostText initiates a WebSocket connection.
  6. GhostText initiates a WebSocket connection.

Repeat this again and we will double that! This seems to be a exponential problem. I would love to know just why a WebSocket close connection is not cleaning up rouge event handlers?

fregante commented 6 years ago

This is caused by the script injection in the extension, every time you click the button it adds a listener, so when you focus the field it will fire all the listeners and each listener will open a connection. Solution: refresh the browser tab

sukima commented 6 years ago

Are you suggesting that the normal operation involves refreshing the browser tab every time you make a change? I'm willing to guess that we have a fundamental misunderstanding of how the protocol functions.

According to the only documentation so far multiple button presses does not suggest multiple listeners.

When a websocket is complete is the server meant to keep it open? What message is sent to say it is done so the websocket closes? If the websockets are not meant to close how are multiple text areas differentiated?

fregante commented 6 years ago

It's a bug.

pandysong commented 5 years ago

I see the same issue. Is it possible this could be resolved?

fregante commented 5 years ago

Try this out! https://github.com/GhostText/GhostText/pull/122

pandysong commented 5 years ago

I have tried. It looks much better. Thank you.