GM_fetch

fetch pollyfill using GM_xmlhttpRequest

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/421384/1134973/GM_fetch.js

نووسەر
nyarau
وەشان
0.0.1.20230104124032
Created
2021-02-07
Updated
2023-01-04
Size
792 Bytes
مۆڵەت
نییە

fetch pollyfill using GM_xmlhttpRequest, not yet 100% replication of fetch API (eg. errors)

Don't forget to add permissions

// @grant    GM_xmlhttpRequest
// @connect  api.example.com

Example

GM_fetch("https://api.example.com/favicon.png", {
    method: 'POST',
    body: JSON.stringify({message: "hello world"}),
    headers: { 'Content-Type': 'application/json' }
}).then(resp=>resp.blob()).then(blob=>{
    open(URL.createObjectURL(blob), "_blank")
})