(details, { abortAfterMs } = {})
| 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.) |
no test coverage detected