/** * Test Playwright proxy authentication specifically */ import { Browser } from '@stock-bot/browser'; async function testPlaywrightProxyAuth() { console.log('๐Ÿ” Testing Playwright Proxy Authentication...'); try { await Browser.initialize({ headless: true, timeout: 15000, blockResources: false, }); console.log('โœ… Browser initialized'); // Test 1: Without proxy console.log('\n๐Ÿ“ Test 1: Without proxy'); const { page: page1, contextId: ctx1 } = await Browser.createPageWithProxy( 'https://httpbin.org/ip' ); let events1 = 0; let ip1 = null; page1.onNetworkEvent(event => { events1++; console.log(` ๐Ÿ“ก Event: ${event.type} ${event.url}`); if (event.type === 'response' && event.url.includes('/ip') && event.responseData) { ip1 = JSON.parse(event.responseData).origin; console.log(` ๐ŸŒ Your IP: ${ip1}`); } }); await page1.waitForLoadState('domcontentloaded'); await new Promise(resolve => setTimeout(resolve, 2000)); await Browser.closeContext(ctx1); console.log(` Events captured: ${events1}`); // Test 2: With proxy using new authentication method console.log('\n๐Ÿ”’ Test 2: With proxy (new auth method)'); const { page: page2, contextId: ctx2 } = await Browser.createPageWithProxy( 'https://httpbin.org/ip', 'http://doimvbnb-US-rotate:w5fpiwrb9895@p.webshare.io:80' ); let events2 = 0; let ip2 = null; page2.onNetworkEvent(event => { events2++; console.log(` ๐Ÿ“ก Event: ${event.type} ${event.url}`); if (event.type === 'response' && event.url.includes('/ip') && event.responseData) { ip2 = JSON.parse(event.responseData).origin; console.log(` ๐Ÿ”„ Proxy IP: ${ip2}`); } }); await page2.waitForLoadState('domcontentloaded'); await new Promise(resolve => setTimeout(resolve, 2000)); await Browser.closeContext(ctx2); console.log(` Events captured: ${events2}`); // Results console.log('\n๐Ÿ“Š Results:'); console.log(` ๐ŸŒ Direct IP: ${ip1 || 'Not captured'}`); console.log(` ๐Ÿ”„ Proxy IP: ${ip2 || 'Not captured'}`); console.log(` ๐Ÿ“ก Direct events: ${events1}`); console.log(` ๐Ÿ“ก Proxy events: ${events2}`); if (ip1 && ip2 && ip1 !== ip2) { console.log('โœ… Proxy authentication is working - different IPs detected!'); return true; } else if (events1 > 0 || events2 > 0) { console.log('โš ๏ธ Network monitoring working, but proxy may not be changing IP'); return true; } else { console.log('โŒ No network events captured'); return false; } } catch (error) { console.error('โŒ Test failed:', error); return false; } finally { await Browser.close(); } } async function testManualPageEvaluation() { console.log('\n๐Ÿงช Test 3: Manual page evaluation (without network monitoring)'); try { await Browser.initialize({ headless: true, timeout: 10000, blockResources: false, }); const { page, contextId } = await Browser.createPageWithProxy( 'https://httpbin.org/ip', 'http://doimvbnb-US-rotate:w5fpiwrb9895@p.webshare.io:80' ); // Try to get the page content directly const title = await page.title(); console.log(` ๐Ÿ“„ Page title: "${title}"`); // Try to evaluate some JavaScript const result = await page.evaluate(() => { return { url: window.location.href, userAgent: navigator.userAgent.substring(0, 50), readyState: document.readyState, }; }); console.log(` ๐Ÿ” Page info:`, result); // Try to get page content const bodyText = await page.locator('body').textContent(); if (bodyText) { console.log(` ๐Ÿ“ Body content (first 200 chars): ${bodyText.substring(0, 200)}...`); // Check if it looks like an IP response if (bodyText.includes('origin')) { console.log(' โœ… Looks like httpbin.org response!'); } } await Browser.closeContext(contextId); return true; } catch (error) { console.error(' โŒ Manual evaluation failed:', error); return false; } finally { await Browser.close(); } } async function runProxyTests() { console.log('๐Ÿš€ Playwright Proxy Authentication Tests\n'); const authResult = await testPlaywrightProxyAuth(); const manualResult = await testManualPageEvaluation(); console.log(`\n๐Ÿ Final Results:`); console.log(` ๐Ÿ” Proxy auth test: ${authResult ? 'โœ… PASS' : 'โŒ FAIL'}`); console.log(` ๐Ÿงช Manual eval test: ${manualResult ? 'โœ… PASS' : 'โŒ FAIL'}`); } if (import.meta.main) { runProxyTests().catch(console.error); } export { testPlaywrightProxyAuth, testManualPageEvaluation };