Skip to content

Commit caa0b20

Browse files
authored
added proxy complience (#914)
* added proxy complience * fixed linter issues * updated test case * excluded for the time being test cases related to reinstalltion in mac * updated * excluded when files are installed * increased timeout for post is reacheble to 2500ms * fixed linter issues * increased to 3500 * changed history for complience with breaking change
1 parent c14ac95 commit caa0b20

File tree

13 files changed

+132
-94
lines changed

13 files changed

+132
-94
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
os: [ubuntu-latest]
14-
node-version: [12, 14, 16, 18, 20]
14+
node-version: [14, 16, 18, 20]
1515
java-version: [11]
1616
include:
1717
- os: macos-latest

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 10.0.0 (2024-06-24)
2+
* BREAKING CHANGE: dropped node12 support, minimum version is node14
3+
* added proxy complience
4+
15
# 9.2.3 (2023-10-21)
26
* fixed onCancel bug with got
37

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Node.js Selenium Standalone [![Test](https://github.com/webdriverio/selenium-standalone/actions/workflows/test.yml/badge.svg?branch=main&event=push)](https://github.com/webdriverio/selenium-standalone/actions/workflows/test.yml) ![Supported node versions](https://img.shields.io/badge/node-12%2C%2013%2C%2014%2C%2015%2C%2016%2C%2017%2C%2018%2C%2019%2C%2020-green)
1+
Node.js Selenium Standalone [![Test](https://github.com/webdriverio/selenium-standalone/actions/workflows/test.yml/badge.svg?branch=main&event=push)](https://github.com/webdriverio/selenium-standalone/actions/workflows/test.yml) ![Supported node versions](https://img.shields.io/badge/node-%2014%2C%2016%2C%2018%2C%2020-green)
22
===========================
33

44
> A node based CLI library for launching [Selenium](http://www.seleniumhq.org/download/) with [WebDriver](https://w3c.github.io/webdriver/) support.

docs/API.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,7 @@ since 9.1.0 it's been checked and killed automatically
139139
## Set `selenium-standalone` Version as NodeJS environment parameter
140140

141141
You can set any version by `process.env.SELENIUM_VERSION=3.141.59` before starting selenium-standalone. Default values are here: [lib/default-config.js](../lib/default-config.js)
142+
143+
## Use the package behind corparate proxy
144+
145+
Should be specified `process.env.HTTP_PROXY=http://proxy-url:port` and `process.env.HTTPS_PROXY=http://proxy-url:port` or the same system envirement variables `HTTP_PROXY=http://proxy-url:port`, `HTTPS_PROXY=http://proxy-url:port`

lib/check-started.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = checkStarted;
22

33
const { default: got } = require('got');
44
const { sleep } = require('./delay');
5+
const { getProxtAgent } = require('./proxyManager');
56

67
async function checkStarted(selenium, seleniumStatusUrl) {
78
const cpState = {
@@ -49,7 +50,7 @@ async function checkStarted(selenium, seleniumStatusUrl) {
4950

5051
try {
5152
// server has one minute to start
52-
await got(seleniumStatusUrl, gotOptions);
53+
await got(seleniumStatusUrl, { ...getProxtAgent(seleniumStatusUrl), ...gotOptions });
5354
selenium.removeListener('exit', errorIfNeverStarted);
5455
return null;
5556
} catch (err) {

lib/compute-download-urls.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const {
1010
getIeDriverArchitectureOld,
1111
getFirefoxDriverArchitectureOld,
1212
} = require('./platformDetection');
13+
const microsoftEdgeReleases = require('./microsoft-edge-releases');
14+
const { getProxtAgent } = require('./proxyManager');
1315

1416
const urls = {
1517
selenium: '%s/%s/selenium-server-standalone-%s.jar',
@@ -188,8 +190,6 @@ async function computeDownloadUrls(options) {
188190
return downloadUrls;
189191
}
190192

191-
const microsoftEdgeReleases = require('./microsoft-edge-releases');
192-
193193
function getEdgeDriverUrl(version) {
194194
const release = microsoftEdgeReleases[version];
195195
if (!release) {
@@ -209,7 +209,7 @@ async function chromiumEdgeBundleAvailable(opts) {
209209
getChromiumEdgeDriverArchitectureOld(opts.drivers.chromiumedge.platform, opts.drivers.chromiumedge.version)
210210
);
211211
try {
212-
await got.head(url, { timeout: 10000 });
212+
await got.head(url, { ...getProxtAgent(url), timeout: 10000 });
213213
} catch (_) {
214214
return false;
215215
}
@@ -247,7 +247,7 @@ async function resolveLatestVersion(opts, browserDriver, url) {
247247

248248
async function getLatestChromium(opts, browserDriver, url) {
249249
try {
250-
const response = await got(url, { timeout: 10000 });
250+
const response = await got(url, { ...getProxtAgent(url), timeout: 10000 });
251251
// edgewebdriver latest version file contains invalid characters
252252
const version = response.body.replace(/\r|\n/g, '').replace(/[^\d|.]/g, '');
253253

@@ -260,10 +260,10 @@ async function getLatestChromium(opts, browserDriver, url) {
260260
}
261261

262262
async function getLatestGeckodriver(opts, browserDriver, url) {
263-
const response = await got(url, { timeout: 10000, responseType: 'json' });
264-
if (typeof response.body.name === 'string' && response.body.name) {
263+
const response = await got(url, { ...getProxtAgent(url), timeout: 10000 }).json();
264+
if (typeof response.name === 'string' && response.name) {
265265
// eslint-disable-next-line no-param-reassign
266-
opts.drivers[browserDriver].version = response.body.name;
266+
opts.drivers[browserDriver].version = response.name;
267267
return true;
268268
}
269269
}
@@ -277,15 +277,18 @@ function resolveDownloadPath(platform, buildId) {
277277
}
278278

279279
async function getLastChromedriverVersionFromMajor(version) {
280+
const url = 'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json';
280281
const response = await got({
281-
method: 'get',
282-
url: 'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json',
283-
responseType: 'json',
284-
headers: {
285-
'Content-Type': 'application/json',
282+
...getProxtAgent(url),
283+
...{
284+
method: 'get',
285+
url: url,
286+
headers: {
287+
'Content-Type': 'application/json',
288+
},
286289
},
287-
});
288-
const versionsWithMajor = response.body.versions.filter(
290+
}).json();
291+
const versionsWithMajor = response.versions.filter(
289292
(f) =>
290293
validateMajorVersionPrefix(f.version) === validateMajorVersionPrefix(version) && 'chromedriver' in f.downloads
291294
);
@@ -299,18 +302,21 @@ async function getLastChromedriverVersionFromMajor(version) {
299302
}
300303

301304
async function getLatestChromeVersion(possibleChanel) {
305+
const url = 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json';
302306
const response = await got({
303-
method: 'get',
304-
url: 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json',
305-
responseType: 'json',
306-
headers: {
307-
'Content-Type': 'application/json',
307+
...getProxtAgent(url),
308+
...{
309+
method: 'get',
310+
url: url,
311+
headers: {
312+
'Content-Type': 'application/json',
313+
},
308314
},
309-
});
310-
const channel = Object.keys(response.body.channels).find((i) => i.toLowerCase() === possibleChanel.toLowerCase());
315+
}).json();
316+
const channel = Object.keys(response.channels).find((i) => i.toLowerCase() === possibleChanel.toLowerCase());
311317

312318
try {
313-
return response.body.channels[channel].version;
319+
return response.channels[channel].version;
314320
} catch (err) {
315321
console.log();
316322
throw new Error(`channel can't be - ${possibleChanel}, possible only Stable, Beta, Dev, Canary`);

lib/install-utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { default: got } = require('got');
99
const debug = require('debug')('selenium-standalone:install');
1010
const { logError } = require('./log-error');
1111
const md5 = require('md5');
12+
const { getProxtAgent } = require('./proxyManager');
1213

1314
const installers = ['selenium', 'chrome', 'ie', 'firefox', 'edge', 'chromiumedge'];
1415

@@ -107,6 +108,7 @@ async function isUpToDate(url, file, pathToFile) {
107108
}
108109
try {
109110
const response = await got.head(url, {
111+
...getProxtAgent(url),
110112
timeout: 2500,
111113
});
112114
if (response.headers['content-length'] === `${fs.statSync(pathToFile).size}`) {

lib/install.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525
} = require('./install-utils');
2626
const { checkArgs } = require('./check-args');
2727
const { logError } = require('./log-error');
28+
const { getProxtAgent } = require('./proxyManager');
2829

2930
/**
3031
* used ONLY to deal with progress bar.
@@ -287,7 +288,7 @@ async function install(_opts) {
287288

288289
async function getDownloadStream(downloadUrl) {
289290
let prevTransferred = 0;
290-
const downloadStream = got.stream(downloadUrl, { ...requestOpts, isStream: true });
291+
const downloadStream = got.stream(downloadUrl, { ...getProxtAgent(downloadUrl), ...requestOpts, isStream: true });
291292
return await new Promise((resolve, reject) => {
292293
downloadStream
293294
.once('response', () => {

lib/proxyManager.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { HttpsProxyAgent } = require('https-proxy-agent');
2+
const { HttpProxyAgent } = require('http-proxy-agent');
3+
/**
4+
* Returns proxy agent if exist.
5+
* @param {string} url
6+
* @returns {any}
7+
*/
8+
function getProxtAgent(url) {
9+
if (url.startsWith('http:') && process.env.HTTP_PROXY) {
10+
const httpProxyAgent = new HttpProxyAgent(process.env.HTTP_PROXY);
11+
return { agent: { http: httpProxyAgent } };
12+
}
13+
if (url.startsWith('https:') && process.env.HTTPS_PROXY) {
14+
const httpProxyAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY);
15+
return { agent: { https: httpProxyAgent } };
16+
}
17+
return {};
18+
}
19+
module.exports = { getProxtAgent };

package-lock.json

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)