-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathopera.js
More file actions
143 lines (122 loc) · 3.9 KB
/
opera.js
File metadata and controls
143 lines (122 loc) · 3.9 KB
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
137
138
139
140
141
142
143
/*! @license
* WebDriver Installer
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
const {WebDriverInstallerBase} = require('./base.js');
const {InstallerUtils} = require('./utils.js');
const os = require('os');
const path = require('path');
class OperaWebDriverInstaller extends WebDriverInstallerBase {
getBrowserName() {
return 'Opera';
}
getDriverName() {
return 'operadriver';
}
/**
* Get installed Opera browser version.
* Handles macOS, Linux (including Snap), and Windows.
*/
async getInstalledBrowserVersion() {
if (os.platform() === 'darwin') {
// Try common macOS bundle names
return (
await InstallerUtils.getMacAppVersion('Opera') ||
await InstallerUtils.getMacAppVersion('Opera Stable')
);
}
if (os.platform() === 'linux') {
// Try Snap installation first
let version = await InstallerUtils.getCommandOutputOrNullIfMissing(
['/snap/bin/opera', '--version']
);
if (!version) {
// Fallback to PATH
version = await InstallerUtils.getCommandOutputOrNullIfMissing(
['opera', '--version']
);
}
// return only version number
return version ? version.trim().split(' ')[0] : null;
}
if (os.platform() === 'win32') {
// Try standard paths
const possiblePaths = [
'C:\\Program Files\\Opera\\opera.exe',
'C:\\Program Files (x86)\\Opera\\opera.exe',
'C:\\Users\\' + os.userInfo().username + '\\AppData\\Local\\Programs\\Opera\\opera.exe',
];
for (const exePath of possiblePaths) {
const version = await InstallerUtils.getWindowsExeVersion(exePath);
if (version) {
return version;
}
}
// Fallback to PATH
return await InstallerUtils.getWindowsExeVersion('opera.exe');
}
throw new Error(`Unsupported platform: ${os.platform()}`);
}
/**
* Get installed OperaDriver version from output directory.
*/
async getInstalledDriverVersion(outputDirectory) {
let outputPath = path.join(outputDirectory, this.getDriverName());
if (os.platform() === 'win32') {
outputPath += '.exe';
}
const output = await InstallerUtils.getCommandOutputOrNullIfMissing(
[outputPath, '--version']
);
// Example: "operadriver 114.0.5735.90 (...)"
return output ? output.trim().split(' ')[1] : null;
}
/**
* Always fetch the latest OperaDriver release from GitHub.
* This avoids 404 errors if the installed Opera version
* does not have a matching driver.
*/
async getBestDriverVersion(_browserVersion) {
const tag = await InstallerUtils.fetchLatestGitHubTag(
'operasoftware/operachromiumdriver'
);
// tag example: "v114.0.5735.90"
return tag.replace(/^v\.?/, '');
}
/**
* Install the OperaDriver binary for the current platform.
*/
async install(driverVersion, outputDirectory) {
let platform;
let binaryName = 'operadriver';
if (os.platform() === 'linux') {
platform = 'linux64';
} else if (os.platform() === 'darwin') {
platform = 'mac64';
} else if (os.platform() === 'win32') {
platform = 'win64';
binaryName += '.exe';
} else {
throw new Error(`Unsupported platform: ${os.platform()}`);
}
const archiveUrl =
`https://github.com/operasoftware/operachromiumdriver/releases/download/` +
`v.${driverVersion}/operadriver_${platform}.zip`;
// IMPORTANT: operadriver is inside a folder in the zip
const nameInArchive = `operadriver_${platform}/${binaryName}`;
let outputName = this.getDriverName();
if (os.platform() === 'win32') {
outputName += '.exe';
}
// Install binary from network archive
return InstallerUtils.installBinary(
archiveUrl,
nameInArchive,
outputName,
outputDirectory,
/* isZip */ true
);
}
}
module.exports = {OperaWebDriverInstaller};