{"id":47772,"library":"gmxhr-fetch","title":"gmxhr-fetch","description":"A fetch-like polyfill for userscript managers (Tampermonkey, Greasemonkey, Violentmonkey). Version 0.1.2 provides a familiar `fetch` interface over `GM_xmlhttpRequest`, allowing userscript authors to use Promise-based HTTP requests without managing raw GM API calls. Lightweight, no external dependencies, supports typical fetch options (method, headers, body). Key differentiator: simplifies migrating from standard fetch to userscript context by mimicking the Fetch API.","status":"active","version":"0.1.2","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install gmxhr-fetch","lang":"bash","label":"npm"},{"cmd":"yarn add gmxhr-fetch","lang":"bash","label":"yarn"},{"cmd":"pnpm add gmxhr-fetch","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; CommonJS require not supported. In userscripts, add @require directive in metablock.","wrong":"const gmfetch = require('gmxhr-fetch')","symbol":"gmfetch","correct":"import { gmfetch } from 'gmxhr-fetch'"},{"note":"When imported as default, the symbol is named `gmfetch`; but the library's default export is also named `gmfetch`. Both work.","wrong":"import { gmfetch } from 'gmxhr-fetch'","symbol":"default","correct":"import gmfetch from 'gmxhr-fetch'"},{"note":"Must grant both `GM_xmlhttpRequest` and `GM.xmlHttpRequest` in metablock for cross-platform compatibility.","wrong":"// @grant GM.xmlHttpRequest","symbol":"GM_xmlhttpRequest","correct":"// @grant GM_xmlhttpRequest"}],"quickstart":{"code":"// ==UserScript==\n// @name         my script\n// @require      https://unpkg.com/gmxhr-fetch\n// @grant        GM_xmlhttpRequest\n// @grant        GM.xmlHttpRequest\n// ==/UserScript==\n\nasync function main() {\n  try {\n    const response = await gmfetch('https://api.example.com/data', {\n      method: 'POST',\n      headers: { 'Content-Type': 'application/json' },\n      body: JSON.stringify({ key: 'value' })\n    });\n    const data = await response.json();\n    console.log('Success:', data);\n  } catch (error) {\n    console.error('Request failed:', error);\n  }\n}\n\nmain();","lang":"javascript","description":"Demonstrates basic usage in a userscript: making a POST request with headers and body, handling response and errors."},"warnings":[{"fix":"Do not rely on Streams or AbortController; use alternative methods if needed.","message":"`gmfetch` does not support streaming (e.g., response.body) or abort signals (AbortController).","severity":"gotcha","affected_versions":"<=0.1.2"},{"fix":"Test response properties before using non-standard ones.","message":"The response object's `.json()`, `.text()`, etc. may not fully mimic the Fetch API response (e.g., statusText, redirected).","severity":"gotcha","affected_versions":"<=0.1.2"},{"fix":"Add both @grant directives to userscript metablock.","message":"Requires both `GM_xmlhttpRequest` and `GM.xmlHttpRequest` grants; missing one may cause silent failures.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Pin version in @require URL or monitor repository for updates.","message":"Package version 0.1.2 is early alpha; API may change without notice.","severity":"deprecated","affected_versions":"=0.1.2"}],"env_vars":null,"search_vec":"'0.1.2':16 'allow':25 'api':39,66 'author':27 'base':32 'bodi':51 'call':40 'context':61 'depend':44 'differenti':53 'extern':43 'familiar':19 'fetch':3,6,20,47,58,65 'fetch-lik':5 'gm':23,38 'gmxhr':2 'gmxhr-fetch':1 'greasemonkey':13 'header':50 'http':33 'interfac':21 'javascript':67 'key':52 'lightweight':41 'like':7 'manag':11,36 'method':49 'migrat':55 'mimick':63 'option':48 'polyfil':8 'promis':31 'promise-bas':30 'provid':17 'raw':37 'request':34 'simplifi':54 'standard':57 'support':45 'tampermonkey':12 'typic':46 'use':29 'userscript':10,26,60 'version':15 'violentmonkey':14 'without':35 'xmlhttprequest':24","created_at":"2026-06-07T16:53:14.180468+00:00","updated_at":"2026-06-07T16:53:14.180468+00:00","problems":[{"fix":"Add `// @require https://unpkg.com/gmxhr-fetch` to metablock and ensure script runs in userscript context.","cause":"Missing @require directive or incorrect import statement (e.g., using require instead of @require).","error":"TypeError: gmfetch is not a function"},{"fix":"Grant both `GM_xmlhttpRequest` and `GM.xmlHttpRequest` in metablock.","cause":"Incorrect @grant directives or using gmfetch outside userscript scope.","error":"gmfetch is not defined"},{"fix":"Add `// @grant GM_xmlhttpRequest` to metablock.","cause":"Missing @grant for GM_xmlhttpRequest.","error":"ReferenceError: GM_xmlhttpRequest is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"gmxhr-fetch","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}