← back to Charge And Explore
support-form/step2-login.cjs
42 lines
// Step 2: on the already-open auth.tesla.com tab, enter email -> Next ->
// password -> Sign In. Screenshots each state. Password read from secrets
// master, never printed.
const fs = require('fs');
const { chromium } = require('/Users/macstudio3/uber-address-fix/node_modules/playwright');
const EMAIL = 'steveabramsdesigns@gmail.com';
const env = fs.readFileSync('/Users/macstudio3/Projects/secrets-manager/.env', 'utf8');
const PASS = (env.match(/^TESLA_PASSWORD=(.*)$/m) || [])[1];
if (!PASS) { console.error('no TESLA_PASSWORD'); process.exit(1); }
(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 found'); process.exit(1); }
const email = page.locator('input[type="email"], input[name="identity"], input#form-input-identity').first();
await email.waitFor({ timeout: 15000 });
await email.fill(EMAIL);
await page.getByRole('button', { name: /next/i }).click();
await page.waitForTimeout(5000);
await page.screenshot({ path: __dirname + '/s2-after-email.png' });
console.log('after email URL:', page.url());
const pw = page.locator('input[type="password"]').first();
if (await pw.count() && await pw.isVisible().catch(() => false)) {
await pw.fill(PASS);
await page.getByRole('button', { name: /sign in/i }).click();
await page.waitForTimeout(7000);
await page.screenshot({ path: __dirname + '/s3-after-password.png' });
console.log('after password URL:', page.url());
const txt = (await page.innerText('body').catch(() => '')).slice(0, 800);
console.log('BODY:', txt.replace(/\n+/g, ' | '));
} else {
console.log('no visible password field yet');
const txt = (await page.innerText('body').catch(() => '')).slice(0, 800);
console.log('BODY:', txt.replace(/\n+/g, ' | '));
}
process.exit(0);
})().catch(e => { console.error('ERR', e.message); process.exit(1); });