1 Star 0 Fork 2

shannonlin/ajax-hook

forked from healthy/ajax-hook 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.d.ts 3.77 KB
一键复制 编辑 原始数据 按行查看 历史
chenyingyan.xy 提交于 2023-06-04 23:41 . fix: double hook error
interface XMLHttpRequestProxy extends XMLHttpRequest {
responseText: string,
readyState: number;
response: any;
responseURL: string;
responseXML: Document | null;
status: number;
statusText: string;
xhr: OriginXMLHttpRequest
}
interface OriginXMLHttpRequest extends XMLHttpRequest {
getProxy(): XMLHttpRequestProxy;
}
interface AttrGetterAndSetter<T = any> {
getter?: (value: T, xhr: OriginXMLHttpRequest) => T;
setter?: (value: T, xhr: OriginXMLHttpRequest) => T;
}
interface XhrRequestConfig {
method: string,
url: string,
headers: any,
body: any,
async: boolean,
user: string,
password: string,
withCredentials: boolean
xhr: OriginXMLHttpRequest,
}
interface XhrResponse {
config: XhrRequestConfig,
headers: any,
response: any,
status: number,
statusText?: string,
}
type XhrErrorType = 'error' | 'timeout' | 'abort'
interface XhrError {
config: XhrRequestConfig,
type: XhrErrorType
}
interface Hooks {
onreadystatechange?: ((this: XMLHttpRequestProxy, xhr: OriginXMLHttpRequest, ev: ProgressEvent) => any) | null;
onabort?: ((this: XMLHttpRequestProxy, xhr: OriginXMLHttpRequest, ev: ProgressEvent) => any) | null;
onerror?: ((this: XMLHttpRequestProxy, xhr: OriginXMLHttpRequest, ev: ProgressEvent) => any) | null;
onload?: ((this: XMLHttpRequestProxy, xhr: OriginXMLHttpRequest, ev: ProgressEvent) => any) | null;
onloadend?: ((this: XMLHttpRequestProxy, xhr: OriginXMLHttpRequest, ev: ProgressEvent) => any) | null;
onloadstart?: ((this: XMLHttpRequestProxy, xhr: OriginXMLHttpRequest, ev: ProgressEvent) => any) | null;
onprogress?: ((this: XMLHttpRequestProxy, xhr: OriginXMLHttpRequest, ev: ProgressEvent) => any) | null;
ontimeout?: ((this: XMLHttpRequestProxy, xhr: OriginXMLHttpRequest, ev: ProgressEvent) => any) | null;
abort?: ((args: Array<any>, xhr: OriginXMLHttpRequest) => any);
getAllResponseHeaders?: (args: Array<any>, xhr: OriginXMLHttpRequest) => any;
getResponseHeader?: (args: Array<any>, xhr: OriginXMLHttpRequest) => any;
open?: (args: Array<any>, xhr: OriginXMLHttpRequest) => any;
overrideMimeType?: (args: Array<any>, xhr: OriginXMLHttpRequest) => any;
send?: (args: Array<any>, xhr: OriginXMLHttpRequest) => any;
setRequestHeader?: (args: Array<any>, xhr: OriginXMLHttpRequest) => any;
addEventListener?: (args: Array<any>, xhr: OriginXMLHttpRequest) => any;
removeEventListener?: (args: Array<any>, xhr: OriginXMLHttpRequest) => any;
response?: AttrGetterAndSetter,
responseText?: AttrGetterAndSetter<string>,
readyState?: AttrGetterAndSetter<number>,
responseType?: AttrGetterAndSetter<XMLHttpRequestResponseType>;
responseURL?: AttrGetterAndSetter<string>;
responseXML?: AttrGetterAndSetter<Document | null>;
status?: AttrGetterAndSetter<number>;
statusText?: AttrGetterAndSetter<string>;
timeout?: AttrGetterAndSetter<number>;
upload?: AttrGetterAndSetter<XMLHttpRequestUpload>;
withCredentials?: AttrGetterAndSetter<boolean>;
}
interface XhrHandler {
resolve(response: XhrResponse): void
reject(err: XhrError): void
}
interface XhrRequestHandler extends XhrHandler {
next(config: XhrRequestConfig): void
}
interface XhrResponseHandler extends XhrHandler {
next(response: XhrResponse): void
}
interface XhrErrorHandler extends XhrHandler {
next(error: XhrError): void
}
interface Proxy {
onRequest?: (config: XhrRequestConfig, handler: XhrRequestHandler) => void,
onResponse?: (response: XhrResponse, handler: XhrResponseHandler) => void,
onError?: (err: XhrError, handler: XhrErrorHandler) => void,
}
export function proxy(proxy: Proxy, win?: Window): { originXhr: XMLHttpRequest, unProxy: () => void };
export function unProxy(win?: Window);
export function hook(hooks: Hooks,win?: Window): { originXhr: XMLHttpRequest, unHook: () => void };
export function unHook(win?: Window);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/shannonlin/ajax-hook.git
git@gitee.com:shannonlin/ajax-hook.git
shannonlin
ajax-hook
ajax-hook
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385