-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-env-proxy.js
More file actions
42 lines (32 loc) · 1.42 KB
/
test-env-proxy.js
File metadata and controls
42 lines (32 loc) · 1.42 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
const puppeteer = require('puppeteer');
async function testProxyWithEnv() {
console.log('🔍 Тест прокси через переменные окружения...');
try {
// Устанавливаем прокси через переменные окружения
process.env.HTTP_PROXY = 'http://qqfL1uPu:WcGxxjVf@166.1.118.214:63574';
process.env.HTTPS_PROXY = 'http://qqfL1uPu:WcGxxjVf@166.1.118.214:63574';
const browser = await puppeteer.launch({
headless: 'new',
args: [
'--no-sandbox',
'--disable-setuid-sandbox'
]
});
const page = await browser.newPage();
console.log('Проверяем IP через прокси...');
await page.goto('https://httpbin.org/ip', { timeout: 30000 });
const content = await page.content();
console.log('Ответ:', content.slice(0, 300));
await browser.close();
console.log('✅ Тест с переменными окружения прошел успешно');
// Очищаем переменные окружения
delete process.env.HTTP_PROXY;
delete process.env.HTTPS_PROXY;
} catch (error) {
console.error('❌ Ошибка в тесте:', error.message);
// Очищаем переменные окружения в случае ошибки
delete process.env.HTTP_PROXY;
delete process.env.HTTPS_PROXY;
}
}
testProxyWithEnv();