-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselenium_node.js
More file actions
48 lines (41 loc) · 1.31 KB
/
Copy pathselenium_node.js
File metadata and controls
48 lines (41 loc) · 1.31 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
// Selenium + ChromeDriver through a local proxy hop.
//
// Start the hop first, in another terminal:
//
// BOTPROXY_USERNAME=pxu1000-0 BOTPROXY_PASSWORD=your-password \
// node node/proxy-hop.js
//
// then run this:
//
// npm install selenium-webdriver
// node examples/selenium_node.js
//
// Chrome never sees a credential, so there is no auth prompt to dismiss, no
// extension to build, and nothing that a Chrome release can take away.
'use strict';
const { Builder, By } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const HOP = '127.0.0.1:8888';
async function main() {
const options = new chrome.Options()
.addArguments(`--proxy-server=http://${HOP}`)
// Chrome bypasses the proxy for localhost unless told otherwise. Harmless
// here, and it keeps a local test server reachable.
.addArguments('--proxy-bypass-list=<-loopback>')
.addArguments('--headless=new');
const driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
try {
await driver.get('https://httpbin.org/ip');
const text = await driver.findElement(By.css('pre')).getText();
console.log('exit IP:', text.trim());
} finally {
await driver.quit();
}
}
main().catch((err) => {
console.error(err);
process.exit(1);
});