quoid / userscripts

An open-source userscript manager for Safari
https://quoid.github.io/userscripts/
GNU General Public License v3.0
3.18k stars 177 forks source link

Investigate `GM.fetch` implementation #467

Open ACTCD opened 1 year ago

ACTCD commented 1 year ago

Similar to GM.xmlHttpRequest, but more modern. Support for streaming features etc.

Investigate whether Cross-origin access can be achieved with something like GM.xmlHttpRequest or otherwise.

Compared to XMLHttpRequest this may be a more complex and bulky wrapper and bridge.

The goal is to follow the standard Fetch API as much as possible.

GM.fetch is just a temporary name, which may be different according to the actual situation.

There is no ETA.

maltoze commented 1 year ago

I have implemented a similar thing in this repo.

related code: https://github.com/yetone/openai-translator/blob/ffe58e170d49480f2d2c417c8de2b2c2d039104f/src/background/index.ts#L28 https://github.com/yetone/openai-translator/blob/main/src/common/background-fetch.ts

what do yout think? willing to send a pr to support streaming feature.

ACTCD commented 1 year ago

@maltoze Thank you for your comment. I need to learn more to accurately assess this issue, which may take some time.

kryptoniancode commented 7 months ago

WebSocket feature in userscript similar to GM_xmlhttpRequest like GM_webSocket.

https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API

Motivation

I want to use websocket for request with url wss://. It is not possible with GM_xmlhttpRequest, I have tried but the request changed to https.

Proposed Solution

Similar to WebSocket class present in browser.

Use Cases

ACTCD commented 7 months ago

@kryptoniancode I don't understand what you are talking about.

Are you having problems using original WebSockets_API directly?

xhr is not the correct API for ws, as well as fetch, why are you commenting under this issue?

ACTCD commented 7 months ago

@kryptoniancode As far as I know, currently WebSocket is not subject to CORS policy. https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#what_requests_use_cors

If you do find this has changed, please cite your sources.

According to the error log you quoted, you are experiencing a CSP issue. Currently page context CSP restrictions in Safari cannot be bypassed. Refer to #106

kryptoniancode commented 7 months ago

Thanks, I have check on some checked on some website it is working.