Stealth Browsing

medium10 minstealth-browser.ts

Some sites treat headless browsers differently. You want human-like typing and mouse movement and a less obvious fingerprint.

What it shows

  • Configure stealth on BrowserSession (or pass stealth: true for the defaults)

The code

stealth-browser.ts
import { Agent, Cogitator } from '@cogitator-ai/core';
import { BrowserSession, browserTools } from '@cogitator-ai/browser';

const apiKey = process.env.GOOGLE_API_KEY;
if (!apiKey) throw new Error('Set GOOGLE_API_KEY');

const session = new BrowserSession({
  headless: true,
  stealth: {
    humanLikeTyping: true,
    humanLikeMouse: true,
    fingerprintRandomization: true,
    blockWebDriver: true,
  },
  viewport: { width: 1920, height: 1080 },
});
await session.start();
console.log('Stealth enabled:', session.stealthEnabled, session.stealthConfig);

const browser = new Agent({
  name: 'stealth-browser',
  model: 'google/gemini-3.5-flash-lite',
  instructions: 'You browse websites with human-like interactions. Take screenshots to observe the page.',
  tools: browserTools(session),
  temperature: 0.3,
  maxIterations: 10,
});

const cog = new Cogitator({ llm: { providers: { google: { apiKey } } } });

try {
  const result = await cog.run(browser, {
    input: 'Go to https://bot.sannysoft.com, then extract the page text and summarize the bot-detection results.',
  });
  console.log(result.output);
} finally {
  await session.close();
  await cog.close();
}

Run it

install · bash
pnpm add @cogitator-ai/core @cogitator-ai/browser playwright
npx playwright install chromium
EnvironmentGOOGLE_API_KEY
run · bash
GOOGLE_API_KEY=your-key npx tsx stealth-browser.ts

Or run the full example from a clone of the repository (keys in .env):

repository · bash
npx tsx examples/browser/03-stealth-agent.ts

Learn more