Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/plugin-utils/lib/BrowserEmulator.ts
1028 views
1
import { IBoundLog } from '@secret-agent/interfaces/ILog';
2
import {
3
BrowserEmulatorClassDecorator,
4
IBrowserEmulator,
5
IBrowserEmulatorClass,
6
ISelectBrowserMeta,
7
} from '@secret-agent/interfaces/ICorePlugin';
8
import { PluginTypes } from '@secret-agent/interfaces/IPluginTypes';
9
import ICorePluginCreateOptions from '@secret-agent/interfaces/ICorePluginCreateOptions';
10
import IBrowserEngine from '@secret-agent/interfaces/IBrowserEngine';
11
import ICorePlugins from '@secret-agent/interfaces/ICorePlugins';
12
import { IVersion } from '@secret-agent/interfaces/IUserAgentOption';
13
import IDeviceProfile from '@secret-agent/interfaces/IDeviceProfile';
14
15
@BrowserEmulatorClassDecorator
16
export default class BrowserEmulator implements IBrowserEmulator {
17
public static readonly id: string;
18
public static readonly type = PluginTypes.BrowserEmulator;
19
20
public readonly id: string;
21
22
public readonly browserName: string;
23
public readonly browserVersion: IVersion;
24
25
public readonly operatingSystemName: string;
26
public readonly operatingSystemVersion: IVersion;
27
public readonly operatingSystemPlatform: string;
28
29
public readonly userAgentString: string;
30
public readonly browserEngine: IBrowserEngine;
31
public readonly logger: IBoundLog;
32
public readonly deviceProfile: IDeviceProfile;
33
34
protected readonly corePlugins: ICorePlugins;
35
36
constructor({
37
userAgentOption,
38
browserEngine,
39
corePlugins,
40
logger,
41
deviceProfile,
42
}: ICorePluginCreateOptions) {
43
this.id = (this.constructor as IBrowserEmulatorClass).id;
44
this.browserName = userAgentOption.browserName;
45
this.browserVersion = userAgentOption.browserVersion;
46
47
this.operatingSystemPlatform = userAgentOption.operatingSystemPlatform;
48
this.operatingSystemName = userAgentOption.operatingSystemName;
49
this.operatingSystemVersion = userAgentOption.operatingSystemVersion;
50
51
this.userAgentString = userAgentOption.string;
52
this.browserEngine = browserEngine;
53
54
this.corePlugins = corePlugins;
55
this.logger = logger;
56
this.deviceProfile = deviceProfile ?? {};
57
}
58
59
// eslint-disable-next-line @typescript-eslint/no-unused-vars
60
public static selectBrowserMeta(userAgentSelector: string): ISelectBrowserMeta {
61
throw new Error('selectBrowserMeta() is missing implementation');
62
}
63
}
64
65