MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / gmRequest

Function gmRequest

example/tests/gm_xhr_test.js:419–440  ·  view source on GitHub ↗
(details, { abortAfterMs } = {})

Source from the content-addressed store, hash-verified

417 }
418
419 function gmRequest(details, { abortAfterMs } = {}) {
420 return new Promise((resolve, reject) => {
421 const t0 = performance.now();
422 const req = GM_xmlhttpRequest({
423 ...details,
424 onload: (res) => resolve({ kind: "load", res, ms: performance.now() - t0 }),
425 onerror: (res) => reject({ kind: "error", res, ms: performance.now() - t0 }),
426 ontimeout: (res) => reject({ kind: "timeout", res, ms: performance.now() - t0 }),
427 onabort: (res) => reject({ kind: "abort", res, ms: performance.now() - t0 }),
428 onprogress: details.onprogress,
429 });
430 if (abortAfterMs != null) {
431 setTimeout(() => {
432 try {
433 req.abort();
434 } catch (_) {
435 /* ignore */
436 }
437 }, abortAfterMs);
438 }
439 });
440 }
441
442 // Switched base host from httpbin to httpbun (faster).
443 // See: https://httpbun.com (endpoints: /get, /post, /bytes/{n}, /delay/{s}, /status/{code}, /redirect-to, /headers, /any, etc.)

Callers 1

runFunction · 0.70

Calls 2

GM_xmlhttpRequestFunction · 0.85
abortMethod · 0.65

Tested by

no test coverage detected