← back to Watches

thibaut-login-debug.js

103 lines

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    headless: 'new',
    executablePath: '/root/.cache/puppeteer/chrome/linux-145.0.7632.46/chrome-linux64/chrome',
    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 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');

  console.log('Navigating to login...');
  await page.goto('https://www.thibautdesign.com/account/login', { waitUntil: 'networkidle2', timeout: 30000 });

  // Screenshot login page first
  await page.screenshot({ path: '/tmp/thibaut-login.png', fullPage: true });
  console.log('Login page screenshot saved');

  // Get all form elements
  const forms = await page.$$eval('form', els => els.map(el => ({
    action: el.action, method: el.method, id: el.id, cls: el.className
  })));
  console.log('Forms:', JSON.stringify(forms, null, 2));

  // Get all buttons
  const buttons = await page.$$eval('button', els => els.map(el => ({
    type: el.type, text: el.innerText.trim(), cls: el.className, id: el.id
  })));
  console.log('Buttons:', JSON.stringify(buttons, null, 2));

  // Check for any hidden fields (CSRF tokens etc)
  const hiddenInputs = await page.$$eval('input[type="hidden"]', els => els.map(el => ({
    name: el.name, value: el.value.substring(0, 50)
  })));
  console.log('Hidden inputs:', JSON.stringify(hiddenInputs, null, 2));

  // Fill in the form
  console.log('\nFilling form...');
  await page.type('#email', 'info@designerwallcoverings.com');
  await page.type('#password', '*Thibautaccess911*');

  // Screenshot after filling
  await page.screenshot({ path: '/tmp/thibaut-login-filled.png' });
  console.log('Filled form screenshot saved');

  // Try to find the submit button more specifically
  const submitInfo = await page.evaluate(() => {
    const forms = document.querySelectorAll('form');
    const result = [];
    forms.forEach((f, i) => {
      const btns = f.querySelectorAll('button, input[type="submit"]');
      btns.forEach(b => {
        result.push({
          formIndex: i,
          formAction: f.action,
          tag: b.tagName,
          type: b.type,
          text: b.innerText || b.value,
          disabled: b.disabled,
          visible: b.offsetParent !== null
        });
      });
    });
    return result;
  });
  console.log('Submit buttons in forms:', JSON.stringify(submitInfo, null, 2));

  // Try submitting the form directly
  console.log('\nSubmitting form via form.submit()...');

  // Monitor navigation
  const navPromise = page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 15000 }).catch(e => console.log('Nav timeout:', e.message));

  await page.evaluate(() => {
    const form = document.querySelector('form[action*="login"]') || document.querySelector('form');
    if (form) {
      console.log('Submitting form with action:', form.action);
      form.submit();
    }
  });

  await navPromise;
  console.log('After submit URL:', page.url());

  // Screenshot after login attempt
  await page.screenshot({ path: '/tmp/thibaut-after-login.png' });
  console.log('After login screenshot saved');

  // Check for error messages
  const errorText = await page.evaluate(() => {
    const errorEls = document.querySelectorAll('[class*="error"], [class*="Error"], .alert, [class*="message"]');
    return Array.from(errorEls).map(e => e.innerText.trim()).filter(t => t.length > 0);
  });
  console.log('Error messages:', errorText);

  // Check page content after login
  const pageText = await page.evaluate(() => document.body.innerText.substring(0, 1000));
  console.log('\nPage text after login:\n', pageText.substring(0, 500));

  await browser.close();
  console.log('\nDone!');
})().catch(e => { console.error('Error:', e.message); process.exit(1); });