Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/interfaces/ICorePlugin.ts
1028 views
1
import { URL } from 'url';
2
import IPluginTypes, { PluginTypes } from './IPluginTypes';
3
import ICorePluginCreateOptions from './ICorePluginCreateOptions';
4
import { IInteractionGroups, IInteractionStep } from './IInteractions';
5
import IInteractionsHelper from './IInteractionsHelper';
6
import IPoint from './IPoint';
7
import IBrowserEngine from './IBrowserEngine';
8
import IUserAgentOption, { IVersion } from './IUserAgentOption';
9
import IDnsSettings from './IDnsSettings';
10
import ITcpSettings from './ITcpSettings';
11
import ITlsSettings from './ITlsSettings';
12
import IHttpResourceLoadDetails from './IHttpResourceLoadDetails';
13
import { IPuppetPage } from './IPuppetPage';
14
import { IPuppetWorker } from './IPuppetWorker';
15
import IDeviceProfile from './IDeviceProfile';
16
import IHttp2ConnectSettings from './IHttp2ConnectSettings';
17
import IHttpSocketAgent from './IHttpSocketAgent';
18
import ISessionCreateOptions from './ISessionCreateOptions';
19
import { IPuppetFrame } from './IPuppetFrame';
20
21
export default interface ICorePlugin
22
extends ICorePluginMethods,
23
IBrowserEmulatorMethods,
24
IHumanEmulatorMethods {
25
id: string;
26
}
27
28
export interface ICorePluginClass {
29
id: string;
30
type: IPluginTypes;
31
new (createOptions: ICorePluginCreateOptions): ICorePlugin;
32
}
33
34
export interface ICorePluginMethods {
35
onClientCommand?(meta: IOnClientCommandMeta, ...args: any[]): Promise<any>;
36
}
37
38
export interface IOnClientCommandMeta {
39
puppetPage: IPuppetPage;
40
puppetFrame: IPuppetFrame;
41
}
42
43
// eslint-disable-next-line @typescript-eslint/no-unused-vars
44
export function CorePluginClassDecorator(constructor: ICorePluginClass): void {}
45
46
// HUMAN EMULATORS ///////////////////////////////////////////////////////////////////////////////////////////////////
47
48
export interface IHumanEmulatorClass {
49
id: string;
50
type: PluginTypes.HumanEmulator;
51
new (createOptions: ICorePluginCreateOptions): IHumanEmulator;
52
}
53
54
export interface IHumanEmulator extends ICorePlugin {
55
id: string;
56
}
57
58
export interface IHumanEmulatorMethods {
59
playInteractions?(
60
interactions: IInteractionGroups,
61
runFn: (interaction: IInteractionStep) => Promise<void>,
62
helper?: IInteractionsHelper,
63
): Promise<void>;
64
getStartingMousePoint?(helper?: IInteractionsHelper): Promise<IPoint>;
65
}
66
67
// decorator for human emulator classes. hacky way to check the class implements statics we need
68
// eslint-disable-next-line @typescript-eslint/no-unused-vars
69
export function HumanEmulatorClassDecorator(constructor: IHumanEmulatorClass): void {}
70
71
// BROWSER EMULATORS ///////////////////////////////////////////////////////////////////////////////////////////////////
72
73
export interface IBrowserEmulatorClass {
74
id: string;
75
type: PluginTypes.BrowserEmulator;
76
selectBrowserMeta(userAgentSelector: string): ISelectBrowserMeta;
77
onBrowserWillLaunch?(
78
browserEngine: IBrowserEngine,
79
launchSettings: {
80
showBrowser?: boolean;
81
disableGpu?: boolean;
82
disableDevtools?: boolean;
83
},
84
): Promise<any> | void;
85
new (createOptions: ICorePluginCreateOptions): IBrowserEmulator;
86
}
87
88
export interface ISelectBrowserMeta {
89
userAgentOption: IUserAgentOption;
90
browserEngine: IBrowserEngine;
91
}
92
93
export interface IBrowserEmulator extends ICorePlugin {
94
id: string;
95
96
browserName: string;
97
browserVersion: IVersion;
98
99
operatingSystemPlatform: string;
100
operatingSystemName: string;
101
operatingSystemVersion: IVersion;
102
103
userAgentString: string;
104
deviceProfile: IDeviceProfile;
105
}
106
107
export interface IBrowserEmulatorMethods {
108
configure?(options: IBrowserEmulatorConfig): Promise<any> | void;
109
110
onDnsConfiguration?(settings: IDnsSettings): Promise<any> | void;
111
onTcpConfiguration?(settings: ITcpSettings): Promise<any> | void;
112
onTlsConfiguration?(settings: ITlsSettings): Promise<any> | void;
113
onHttpAgentInitialized?(agent: IHttpSocketAgent): Promise<any> | void;
114
115
onHttp2SessionConnect?(
116
request: IHttpResourceLoadDetails,
117
settings: IHttp2ConnectSettings,
118
): Promise<any> | void;
119
beforeHttpRequest?(request: IHttpResourceLoadDetails): Promise<any> | void;
120
beforeHttpResponse?(resource: IHttpResourceLoadDetails): Promise<any> | void;
121
122
onNewPuppetPage?(page: IPuppetPage): Promise<any>;
123
onNewPuppetWorker?(worker: IPuppetWorker): Promise<any>;
124
125
websiteHasFirstPartyInteraction?(url: URL): Promise<any> | void; // needed for implementing first-party cookies
126
}
127
128
export type IBrowserEmulatorConfig = Pick<
129
ISessionCreateOptions,
130
'viewport' | 'geolocation' | 'timezoneId' | 'locale' | 'upstreamProxyIpMask' | 'upstreamProxyUrl'
131
>;
132
133
// decorator for browser emulator classes. hacky way to check the class implements statics we need
134
// eslint-disable-next-line @typescript-eslint/no-unused-vars
135
export function BrowserEmulatorClassDecorator(constructor: IBrowserEmulatorClass): void {}
136
137