import puppeteer from 'puppeteer';

async function testPuppeteer() {
  const browser = await puppeteer.launch({
    headless: 'new',
    args: [
      '--no-sandbox',
      '--disable-setuid-sandbox',
      '--disable-dev-shm-usage'
    ]
  });

  const page = await browser.newPage();
  await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36');

  const url = 'https://manhwaweb.com/manga/one-piece_1695365223767';
  console.log('Navigating to:', url);

  await page.goto(url, {
    waitUntil: 'networkidle0',
    timeout: 30000
  });

  console.log('Waiting 3 seconds for content to load...');
  await page.waitForTimeout(3000);

  // Get page title
  const title = await page.title();
  console.log('Page title:', title);

  // Look for links with /leer/
  const links = await page.evaluate(() => {
    const allLinks = Array.from(document.querySelectorAll('a'));
    const leerLinks = allLinks
      .filter(a => a.href && a.href.includes('/leer/'))
      .slice(0, 10)
      .map(a => ({
        href: a.href,
        text: a.textContent?.trim()
      }));

    return leerLinks;
  });

  console.log(`\nFound ${links.length} links with /leer/:`);
  links.forEach(link => {
    console.log(`  - ${link.href}: "${link.text}"`);
  });

  await browser.close();
}

testPuppeteer().catch(console.error);
