UNPKG

mock-violentmonkey

Version:

Mock violentmonkey's globals for testing userscripts

53 lines (52 loc) 2.55 kB
import type { JsonValue } from '../type-helpers.js'; import { type Headers, type Method } from '../xmlhttprequest/index.js'; type XHRResponseObject<TContext = any> = { status: number; statusText: string; readyState: number; responseHeaders: string; response: string | Blob | ArrayBuffer | Document | JsonValue | null; responseText: string | undefined; finalUrl: string; context: TContext; }; type XHREventHandler<TContext = any> = (responseObject: XHRResponseObject<TContext>) => void | Promise<void>; type XHRDetails<TContext = any> = { /** URL relative to current page is also allowed. */ url: string; /** Usually GET. */ method?: Method | undefined; /** User for authentication. */ user?: string | undefined; /** Password for authentication. */ password?: string | undefined; /** A MIME type to specify with the request. */ overrideMimeType?: string | undefined; headers?: Headers | undefined; /** Defaults to 'text'. */ responseType?: 'text' | 'json' | 'blob' | 'arraybuffer' | 'document' | undefined; /** Time to wait for the request, none by default. */ timeout?: number | undefined; /** Data to send with the request, usually for POST and PUT requests. */ data?: string | FormData | Blob; /** Send the data string as a blob. This is for compatibility with Tampermonkey/Greasemonkey, where only string type is allowed in data */ binary?: boolean | undefined; /** Can be an object and will be assigned to context of the response object. */ context?: TContext; /** When set to true, no cookie will be sent with the request and since VM2.12.5 the response cookies will be ignored. The default value is false. */ anonymous?: boolean | undefined; onabort?: XHREventHandler<TContext> | undefined; onerror?: XHREventHandler<TContext> | undefined; onload?: XHREventHandler<TContext> | undefined; onloadend?: XHREventHandler<TContext> | undefined; onloadstart?: XHREventHandler<TContext> | undefined; onprogress?: XHREventHandler<TContext> | undefined; onreadystatechange?: XHREventHandler<TContext> | undefined; ontimeout?: XHREventHandler<TContext> | undefined; }; type XmlHttpRequest = <TContext>(details: XHRDetails<TContext>) => { abort: () => void; }; declare const xmlhttpRequest: XmlHttpRequest; export type { Headers } from '../xmlhttprequest/index.js'; export { type XHRDetails, type XHREventHandler, type XHRResponseObject, type XmlHttpRequest, xmlhttpRequest as GM_xmlhttpRequest, };