-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.ts
136 lines (129 loc) · 4.59 KB
/
base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import type Puppeteer from 'puppeteer' // ContinueRequestOverrides
import type { Agent } from 'http'
import type { Hooks } from 'got'
import { IInterceptionProxyRequest } from './classes';
import { IResponseOptions, RequestMode } from './network'
export interface ILogObject {
level: 'error' | 'warning' | 'info' | 'debug',
message: string,
error?: any, // TODO: fill missing type? (10)
meta: Array<any>,
}
export declare function Logger(logObject: ILogObject): void
export interface IBaseRequestHookOptions {
key: string | symbol;
priority: number;
// disabled?: boolean;
isLocal?: boolean;
// handler: (...args: any[]) => any;
}
export type IRequestHandler = (request: IInterceptionProxyRequest) => void | IResponseOptions | Promise<void | IResponseOptions>
export type IRequestListener = (request: IInterceptionProxyRequest) => void | true | Promise<void | true>
export interface IRequestHandlerOptions extends IBaseRequestHookOptions {
handler: IRequestHandler;
}
export interface IRequestListenerOptions extends IBaseRequestHookOptions {
handler: IRequestListener;
}
export interface IRequestEventOptionsMap {
requestHandlers: IRequestHandlerOptions,
requestListeners: IRequestListenerOptions,
}
/**
* Plugin configuration object
*/
export interface IConfig {
/**
* Puppeteer' "Cooperative Intercept Mode" `priority`
*
* This package using own way to manage cooperation
*
* Use only if you know what it does
*
* [[Read more]](https://github.com/puppeteer/puppeteer/blob/v10.2.0/docs/api.md#cooperative-intercept-mode-and-legacy-intercept-mode)
*/
cooperativePriority: undefined | number;
/**
* `ignore` - Plugin will do nothing about original request
*
* `native` - Plugin will just listen to the original request/response data and all requests will fulfilled by puppeteer itself. But some plugin functionality can be unavailable.
*
* `managed` - Plugin will do all requests by `requestHandlers` or by himself. All plugin features will be available.
*
* Default - managed
*/
requestMode: RequestMode;
/**
* Proxy for request
*
* Automatically sets `agent` property using [proxy-agent](https://www.npmjs.com/package/proxy-agent)
*
* Examples:
* - `http://proxy-server-over-tcp.com:3128`
* - `https://proxy-server-over-tls.com:3129`
* - `socks://username:password@some-socks-proxy.com:9050` (username & password are optional)
* - `socks5://username:password@some-socks-proxy.com:9050` (username & password are optional)
* - `socks4://some-socks-proxy.com:9050`
* - `pac+http://www.example.com/proxy.pac`
*
* Default `null`
*/
proxy: string | null, // TODO: fill missing type
/**
* Your agent hot handling requests
*
* Sets by `proxy` property. Cleans `proxy` property if sets directly.
*
* Default `null`
*
* @deprecated Use `proxy` property instead.
* Deprecated because of possibly incoming request handling rework.
*/
agent: Agent | null,
/**
* You can handle all plugins messages
*/
logger: typeof Logger;
/**
* Request timeout in milliseconds(actual execution only)
*/
timeout: number;
// attempts: number;
/**
* If you didn't changed request or response, let puppeteer handle this request by himself
*
* Default: `false`
*/
nativeContinueIfPossible: boolean;
/**
* If you did not use the plugin' response object it will not retrieve response from puppeteer
* for better performance
*
* Applies for `native` mode only
*
* @dev Affects the operation of the `getResponse` only if it is set to direct or
* the response object was not explicitly received while working with the request
*/
ignoreResponseBodyIfPossible: boolean,
/**
* For old versions of puppeteer, plugin should handle cookies by himself.
*
* Enable this option, if you are have an issue with cookie.
*
* Recommended to upgrade your puppeteer version instead.
*/
enableLegacyCookieHandling: boolean;
/**
* It is not recommended to use. Use another library properties to do it.
*
* Modify requests in more advanced way through interaction with got.
*
* @see https://github.com/sindresorhus/got/blob/main/documentation/9-hooks.md
*/
gotHooks: Hooks,
requestHandlers: IRequestHandlerOptions[];
requestListeners: IRequestListenerOptions[];
}
export interface IPage extends Puppeteer.Page {
// interceptionConfig: any?;
}