google-ai-mode
v1.0.1
Published
A minimal npm library to scrape Google AI Mode responses using patchright.
Maintainers
Readme
google-ai-mode
A clean, minimal, and production-ready npm library to scrape and extract text from Google AI Mode, powered by Patchright.
Features
- TypeScript First: Strict typing, interfaces, and documented code.
- Production Ready: Graceful browser management, randomized waiting logic, and structured errors.
- Minimal API: Specifically exposes a simple
GoogleAiMode.generateTextPromise-based method. - Universal: ESM and CommonJS exports.
- Anti-Bot Techniques: Automates consent banners and integrates persistent sessions to mitigate standard blocks.
Installation
npm install google-ai-modeUsage
import { GoogleAiMode } from "google-ai-mode";
async function run() {
try {
const response = await GoogleAiMode.generateText(
"What is the capital of France?"
);
console.log("AI Response:", response);
} catch (error) {
console.error("Failed to generate text:", error);
}
}
run();Advanced Configuration
You can pass ScraperOptions to configure the underlying browser.
import { GoogleAiMode } from "google-ai-mode";
const response = await GoogleAiMode.generateText("Explain quantum computing in one sentence", {
headless: false, // Default: true (set to false for debugging or bypassing login locks)
timeout: 120_000, // Default: 60,000 (ms)
userDataDir: "./my-dir" // Persist session to a custom directory instead of a temp folder
});Important Notes
Google heavily rate-limits automated headless queries. If you trigger an AI Mode is not currently available fallback or receive a CAPTCHA exception, you should manually clear the userDataDir or run the program once with headless: false to complete a standard Google login.
License
MIT
