← back to Charge And Explore

support-form/step4-captcha.cjs

29 lines

// Step 4: click the hCaptcha checkbox inside its iframe, then submit if it
// clears without a visual challenge.
const { chromium } = require('/Users/macstudio3/uber-address-fix/node_modules/playwright');

(async () => {
  const browser = await chromium.connectOverCDP('http://127.0.0.1:9223');
  const ctx = browser.contexts()[0];
  const page = ctx.pages().find(p => p.url().includes('auth.tesla.com'));
  if (!page) { console.error('no tesla tab'); process.exit(1); }

  const cbFrame = page.frameLocator('iframe[title*="hCaptcha" i], iframe[src*="hcaptcha"]').first();
  await cbFrame.locator('#checkbox, div[role="checkbox"]').first().click({ timeout: 15000 });
  await page.waitForTimeout(6000);
  await page.screenshot({ path: __dirname + '/s4a-after-captcha-click.png' });

  const btn = page.getByRole('button', { name: /sign in/i });
  const enabled = await btn.isEnabled().catch(() => false);
  console.log('sign-in enabled:', enabled);
  if (enabled) {
    await btn.click();
    await page.waitForTimeout(9000);
    console.log('after submit URL:', page.url());
    await page.screenshot({ path: __dirname + '/s4b-after-submit.png' });
    const txt = (await page.innerText('body').catch(() => '')).slice(0, 900);
    console.log('BODY:', txt.replace(/\n+/g, ' | '));
  }
  process.exit(0);
})().catch(e => { console.error('ERR', e.message); process.exit(1); });