Files
cannaiq/backend/test-no-proxy.ts
2025-11-28 19:45:44 -07:00

86 lines
2.4 KiB
TypeScript

import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
puppeteer.use(StealthPlugin());
async function testNoProxy() {
let browser;
try {
console.log('🌐 Testing WITHOUT proxy...');
console.log('');
// NO PROXY
browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
const url = 'https://curaleaf.com/stores/curaleaf-dispensary-phoenix-airport/brands';
console.log('Going to:', url);
await page.goto(url, { waitUntil: 'networkidle2', timeout: 60000 });
await page.waitForTimeout(3000);
console.log('Current URL:', page.url());
if (page.url().includes('/age-gate')) {
console.log('\n═══ HANDLING AGE GATE ═══');
// Click dropdown
await page.waitForSelector('button[role="combobox"]', { timeout: 10000 });
await page.click('button[role="combobox"]');
console.log('✅ Clicked dropdown');
await page.waitForTimeout(2000);
// Take screenshot before clicking Arizona
await page.screenshot({ path: '/tmp/before-arizona.png' });
console.log('📸 Screenshot saved: /tmp/before-arizona.png');
// Click Arizona option with real Puppeteer click
const clicked = await page.evaluate(() => {
const options = Array.from(document.querySelectorAll('[role="option"]'));
const azOption = options.find(opt =>
opt.textContent?.toLowerCase().trim() === 'arizona'
) as HTMLElement;
if (azOption) {
azOption.click();
return true;
}
return false;
});
console.log('✅ Clicked Arizona:', clicked);
// Wait for page to update
await page.waitForTimeout(5000);
// Take screenshot after
await page.screenshot({ path: '/tmp/after-arizona.png' });
console.log('📸 Screenshot saved: /tmp/after-arizona.png');
console.log('Current URL:', page.url());
// Check page content
const content = await page.evaluate(() => ({
title: document.title,
text: document.body.innerText.substring(0, 500)
}));
console.log('\nPage title:', content.title);
console.log('Page text:', content.text);
}
} catch (error: any) {
console.error('❌ Error:', error.message);
} finally {
if (browser) await browser.close();
}
}
testNoProxy();