zhengbangbo / chat-gpt-userscript

A userscript to display ChatGPT answer alongside Search Engine or Translator
https://greasyfork.org/scripts/456077
MIT License
79 stars 14 forks source link

Need Support SSE(text/stream) #1

Closed zhengbangbo closed 1 year ago

zhengbangbo commented 1 year ago

At present, there is no verbatim print effect, but the result is printed directly after waiting for a period of time.

This is because there is only GM_xmlhttpRequest() in userscript, but there is no GM_fetch(). In the project I refer to, it uses Fetch to receive data of type text/stream. This is also the method I saw in MDN.

I haven't found a good implementation to use GM_xmlhttpRequest() to support parsing text/stream.

Just now, I found that GM_xmlhttpRequest() has a fetch attribute, but the document shows that he is in the beta state^doc. I'm not sure it works.

If you are a userscript master, I hope you can give me some help. Thank you.

zhengbangbo commented 1 year ago

https://github.com/Tampermonkey/tampermonkey/issues/1278 is explained that the data is stored in memory before it is fully received, so it is impossible to obtain the data segment by segment, so it cannot be printed verbatim, and it will take a long time to wait.😭.

The streaming is the core difference between XMLHttpRequest and fetch.

When you download some data with XMLHttpRequest the entire data stores in the memory until the request is finished and data is handled. In case of a userscript manager extension the consuming of memory is double. Since the data stores both in content/web script and in the background script.

zhengbangbo commented 1 year ago

v0.5.0 Tampermonkey support print verbatim

36e88e65e12595e3bbd1cf2a7d6bb9afbcbf7750