111 lines
3.8 KiB
TypeScript
111 lines
3.8 KiB
TypeScript
import puppeteer from 'puppeteer';
|
||
import { setAgeGateCookies, bypassAgeGate, hasAgeGate } from './src/utils/age-gate';
|
||
|
||
const TEST_URL = 'https://dutchie.com/dispensary/sol-flower-dispensary';
|
||
|
||
async function testSolFlowerAgeGate() {
|
||
console.log('\n🧪 Testing Sol Flower Dispensary Age Gate\n');
|
||
console.log(`URL: ${TEST_URL}\n`);
|
||
|
||
const browser = await puppeteer.launch({
|
||
headless: true, // Run in headless mode
|
||
args: [
|
||
'--no-sandbox',
|
||
'--disable-setuid-sandbox',
|
||
'--disable-blink-features=AutomationControlled',
|
||
'--disable-features=IsolateOrigins,site-per-process',
|
||
'--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
||
]
|
||
});
|
||
|
||
try {
|
||
const page = await browser.newPage();
|
||
|
||
// Set viewport
|
||
await page.setViewport({ width: 1280, height: 720 });
|
||
|
||
console.log('📍 Step 1: Setting age gate cookies...');
|
||
await setAgeGateCookies(page, TEST_URL, 'Arizona');
|
||
|
||
console.log('📍 Step 2: Navigating to page...');
|
||
await page.goto(TEST_URL, { waitUntil: 'domcontentloaded', timeout: 60000 });
|
||
await page.waitForTimeout(3000);
|
||
|
||
const currentUrl = page.url();
|
||
console.log(`Current URL: ${currentUrl}`);
|
||
|
||
console.log('\n📍 Step 3: Checking for age gate...');
|
||
const hasGate = await hasAgeGate(page);
|
||
|
||
if (hasGate) {
|
||
console.log('✅ Age gate detected!');
|
||
|
||
// Take screenshot before bypass
|
||
await page.screenshot({ path: '/tmp/sol-flower-before-bypass.png' });
|
||
console.log('📸 Screenshot saved: /tmp/sol-flower-before-bypass.png');
|
||
|
||
// Get page HTML to analyze structure
|
||
const bodyHTML = await page.evaluate(() => document.body.innerHTML);
|
||
console.log('\n🔍 Page HTML (first 1000 chars):');
|
||
console.log(bodyHTML.substring(0, 1000));
|
||
|
||
console.log('\n📍 Step 4: Attempting to bypass age gate...');
|
||
const bypassed = await bypassAgeGate(page, 'Arizona');
|
||
|
||
if (bypassed) {
|
||
console.log('✅ Age gate bypass succeeded!');
|
||
|
||
// Take screenshot after bypass
|
||
await page.screenshot({ path: '/tmp/sol-flower-after-bypass.png' });
|
||
console.log('📸 Screenshot saved: /tmp/sol-flower-after-bypass.png');
|
||
|
||
const finalUrl = page.url();
|
||
console.log(`Final URL: ${finalUrl}`);
|
||
|
||
// Check if we can see products
|
||
await page.waitForTimeout(3000);
|
||
const hasProducts = await page.evaluate(() => {
|
||
const bodyText = document.body.textContent || '';
|
||
return bodyText.includes('Add to cart') ||
|
||
bodyText.includes('products') ||
|
||
bodyText.includes('shop');
|
||
});
|
||
|
||
console.log(`Can see products: ${hasProducts ? '✅' : '❌'}`);
|
||
} else {
|
||
console.log('❌ Age gate bypass failed');
|
||
|
||
// Take screenshot after failed bypass
|
||
await page.screenshot({ path: '/tmp/sol-flower-failed-bypass.png' });
|
||
console.log('📸 Screenshot saved: /tmp/sol-flower-failed-bypass.png');
|
||
}
|
||
} else {
|
||
console.log('ℹ️ No age gate detected - cookies may have worked!');
|
||
|
||
// Take screenshot
|
||
await page.screenshot({ path: '/tmp/sol-flower-no-gate.png' });
|
||
console.log('📸 Screenshot saved: /tmp/sol-flower-no-gate.png');
|
||
|
||
// Check if we can see products
|
||
const hasProducts = await page.evaluate(() => {
|
||
const bodyText = document.body.textContent || '';
|
||
return bodyText.includes('Add to cart') ||
|
||
bodyText.includes('products') ||
|
||
bodyText.includes('shop');
|
||
});
|
||
|
||
console.log(`Can see products: ${hasProducts ? '✅' : '❌'}`);
|
||
}
|
||
|
||
// Don't pause in headless mode
|
||
|
||
} catch (error) {
|
||
console.error('❌ Error:', error);
|
||
} finally {
|
||
await browser.close();
|
||
console.log('\n✅ Test completed');
|
||
}
|
||
}
|
||
|
||
testSolFlowerAgeGate();
|