import puppeteer from 'puppeteer-extra'; import StealthPlugin from 'puppeteer-extra-plugin-stealth'; import { bypassAgeGate, detectStateFromUrl } from './src/utils/age-gate'; import { Browser, Page } from 'puppeteer'; puppeteer.use(StealthPlugin()); async function debugDutchieDetection() { let browser: Browser | null = null; try { const url = 'https://curaleaf.com/stores/curaleaf-az-48th-street'; browser = await puppeteer.launch({ headless: 'new', args: [ '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-blink-features=AutomationControlled' ] }); const page = await browser.newPage(); await page.setViewport({ width: 1920, height: 1080 }); await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'); console.log('Loading page...'); await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 60000 }); await page.waitForTimeout(3000); console.log('Bypassing age gate...'); const state = detectStateFromUrl(url); await bypassAgeGate(page, state); console.log('\nWaiting 5 more seconds for Dutchie menu to load...'); await page.waitForTimeout(5000); console.log('\nChecking for Dutchie markers...'); const dutchieInfo = await page.evaluate(() => { // Check window.reactEnv const hasReactEnv = !!(window as any).reactEnv; const reactEnvDetails = hasReactEnv ? JSON.stringify((window as any).reactEnv, null, 2) : null; // Check HTML content const htmlContent = document.documentElement.innerHTML; const hasAdminDutchie = htmlContent.includes('admin.dutchie.com'); const hasApiDutchie = htmlContent.includes('api.dutchie.com'); const hasEmbeddedMenu = htmlContent.includes('embedded-menu'); const hasReactEnvInHtml = htmlContent.includes('window.reactEnv'); // Check for Dutchie-specific elements const hasProductListItems = document.querySelectorAll('[data-testid="product-list-item"]').length; const hasDutchieScript = !!document.querySelector('script[src*="dutchie"]'); // Check meta tags const metaTags = Array.from(document.querySelectorAll('meta')).map(m => ({ name: m.getAttribute('name'), content: m.getAttribute('content'), property: m.getAttribute('property') })).filter(m => m.name || m.property); return { hasReactEnv, reactEnvDetails, hasAdminDutchie, hasApiDutchie, hasEmbeddedMenu, hasReactEnvInHtml, hasProductListItems, hasDutchieScript, metaTags, pageTitle: document.title, url: window.location.href }; }); console.log('\n=== Dutchie Detection Results ==='); console.log('window.reactEnv exists:', dutchieInfo.hasReactEnv); if (dutchieInfo.reactEnvDetails) { console.log('window.reactEnv contents:', dutchieInfo.reactEnvDetails); } console.log('Has admin.dutchie.com in HTML:', dutchieInfo.hasAdminDutchie); console.log('Has api.dutchie.com in HTML:', dutchieInfo.hasApiDutchie); console.log('Has "embedded-menu" in HTML:', dutchieInfo.hasEmbeddedMenu); console.log('Has "window.reactEnv" in HTML:', dutchieInfo.hasReactEnvInHtml); console.log('Product list items found:', dutchieInfo.hasProductListItems); console.log('Has Dutchie script tag:', dutchieInfo.hasDutchieScript); console.log('Page title:', dutchieInfo.pageTitle); console.log('Current URL:', dutchieInfo.url); await browser.close(); process.exit(0); } catch (error) { console.error('Error:', error); if (browser) await browser.close(); process.exit(1); } } debugDutchieDetection();