|
| 1 | +import { chromium } from 'playwright'; |
| 2 | +import { readFileSync } from 'fs'; |
| 3 | +import { homedir } from 'os'; |
| 4 | +import { join } from 'path'; |
| 5 | + |
| 6 | +const sessionPath = join(homedir(), '.veil', 'sessions', 'x.json'); |
| 7 | +const data = JSON.parse(readFileSync(sessionPath, 'utf-8')); |
| 8 | +const cookies = data.cookies ?? []; |
| 9 | +const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'; |
| 10 | + |
| 11 | +function delay(min: number, max = min * 1.4) { |
| 12 | + return new Promise(r => setTimeout(r, Math.floor(Math.random() * (max - min) + min))); |
| 13 | +} |
| 14 | + |
| 15 | +async function postTweet(page: any, text: string, label: string) { |
| 16 | + await page.goto('https://x.com/home', { waitUntil: 'domcontentloaded', timeout: 30000 }); |
| 17 | + await page.waitForSelector("[data-testid='primaryColumn']", { timeout: 20000 }); |
| 18 | + await delay(1200, 1800); |
| 19 | + await page.locator("[data-testid='tweetTextarea_0']").first().click({ force: true }); |
| 20 | + await delay(400, 600); |
| 21 | + await page.keyboard.type(text, { delay: 38 }); |
| 22 | + await delay(700, 1000); |
| 23 | + await page.locator("[data-testid='tweetButtonInline']").first().click({ force: true }); |
| 24 | + await delay(2500, 3200); |
| 25 | + console.log(`✅ Posted: ${label}`); |
| 26 | + // Return URL of posted tweet by checking profile |
| 27 | + const postedText = text.slice(0, 40); |
| 28 | + return postedText; |
| 29 | +} |
| 30 | + |
| 31 | +const browser = await chromium.launch({ headless: true, args: ['--no-sandbox', '--disable-blink-features=AutomationControlled'] }); |
| 32 | +const context = await browser.newContext({ userAgent: UA, viewport: { width: 1280, height: 800 }, locale: 'en-US' }); |
| 33 | +await context.addInitScript(() => { Object.defineProperty(navigator, 'webdriver', { get: () => undefined }); }); |
| 34 | +await context.addCookies(cookies); |
| 35 | +const page = await context.newPage(); |
| 36 | + |
| 37 | +// ── TWEET 1: The announcement ──────────────────────────────────────────────── |
| 38 | +await postTweet(page, `Shipping something new. |
| 39 | +
|
| 40 | +veil — a stealth browser remote for AI agents. |
| 41 | +
|
| 42 | +Post, like, reply, quote on X. Navigate any website. Every action returns clean JSON. |
| 43 | +
|
| 44 | +You're the brain. veil is the hands. |
| 45 | +
|
| 46 | +npm install -g veil-browser |
| 47 | +
|
| 48 | +→ github.com/cuttlelab/veil`, 'Announcement'); |
| 49 | + |
| 50 | +await delay(8000, 12000); // natural gap between posts |
| 51 | + |
| 52 | +// ── TWEET 2: The demo ──────────────────────────────────────────────────────── |
| 53 | +await postTweet(page, `What it looks like: |
| 54 | +
|
| 55 | +$ veil login x |
| 56 | +$ veil post "hello world" |
| 57 | +$ veil like --nth 0 |
| 58 | +$ veil reply "great point" --nth 0 |
| 59 | +$ veil quote "worth reading" --nth 2 |
| 60 | +
|
| 61 | +That's it. Real browser. Stealth. JSON output. No LLM inside — your agent decides every step.`, 'Demo'); |
| 62 | + |
| 63 | +await delay(8000, 12000); |
| 64 | + |
| 65 | +// ── TWEET 3: The why ───────────────────────────────────────────────────────── |
| 66 | +await postTweet(page, `Why veil? |
| 67 | +
|
| 68 | +Most browser automation is built for developers writing scripts. |
| 69 | +
|
| 70 | +veil is built for AI agents making decisions in real-time — where every step is a tool call and the agent decides what happens next. |
| 71 | +
|
| 72 | +Open source. MIT. Built at CUTTLELAB. |
| 73 | +
|
| 74 | +→ cuttlelab.github.io/veil`, 'Why'); |
| 75 | + |
| 76 | +console.log('\n🎉 All 3 launch tweets posted!'); |
| 77 | +await browser.close(); |
0 commit comments