Version 1.0
Build a TypeScript-based tool using Playwright/Puppeteer with stealth plugins to monitor Amazon’s Whole Foods organic eggs page, avoid CAPTCHAs, and send alerts when items are in stock.
- Headless browser automation with human-like behavior.
- CAPTCHA avoidance via stealth plugins and IP rotation.
- SMS/email notifications when stock is detected.
- Configurable check intervals and retry logic.
Component | Details |
---|---|
Language | TypeScript |
Browser Engine | Playwright (recommended) or Puppeteer with puppeteer-extra plugins |
Stealth Plugins | puppeteer-extra-plugin-stealth , playwright-stealth |
Proxies | Rotating residential proxies (e.g., Bright Data, Oxylabs) |
Notifications | Twilio (SMS) or Nodemailer (email) |
- Stealth Browser Instance
- Launches headless Chrome/Firefox with randomized fingerprints.
- Uses plugins to hide automation traces (e.g., WebDriver flags, headless detection).
- Monitoring Logic
- Navigates to the Amazon URL, checks for "Add to Cart" buttons.
- Notification Manager
- Triggers alerts via SMS/email when stock is detected.
- Configuration
- Proxy rotation, check intervals, and user-agent lists.
- Initialize stealth browser with proxies.
- Navigate to the Amazon product page.
- Check for "Add to Cart" text or buttons.
- If in stock → send alert.
- If CAPTCHA detected → retry with new IP or notify.
npm init -y
npm install playwright playwright-extra playwright-stealth twilio nodemailer
npm install -D typescript @types/node ts-node
export const config = {
URL: "https://www.amazon.com/s?k=organic+eggs&i=wholefoods",
CHECK_INTERVAL_MIN: 5,
PROXY: "http://user:pass@proxy-ip:port", // From proxy service
TWILIO: {
ACCOUNT_SID: "your_sid",
AUTH_TOKEN: "your_token",
FROM_NUMBER: "+1234567890",
TO_NUMBER: "+0987654321",
},
USER_AGENTS: [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64)...",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)...",
],
};
import { chromium } from "playwright-extra";
import stealth from "playwright-stealth";
import { config } from "./config";
import Twilio from "twilio";
// Apply stealth plugins
chromium.use(stealth);
const twilioClient = Twilio(config.TWILIO.ACCOUNT_SID, config.TWILIO.AUTH_TOKEN);
async function checkStock() {
const browser = await chromium.launch({
headless: true,
proxy: { server: config.PROXY }, // Rotate proxies here
});
const context = await browser.newContext({
userAgent: config.USER_AGENTS[Math.floor(Math.random() * config.USER_AGENTS.length)],
});
const page = await context.newPage();
await page.goto(config.URL, { waitUntil: "networkidle" });
// Check for "Add to Cart"
const isInStock = await page.$('text="Add to Cart"');
await browser.close();
return !!isInStock;
}
async function sendSms() {
await twilioClient.messages.create({
body: "Organic Eggs are IN STOCK!",
from: config.TWILIO.FROM_NUMBER,
to: config.TWILIO.TO_NUMBER,
});
}
(async () => {
while (true) {
try {
const inStock = await checkStock();
if (inStock) {
await sendSms();
break; // Stop after alerting
}
} catch (error) {
console.error("Error:", error);
// Rotate proxy/retry logic here
}
await new Promise((resolve) =>
setTimeout(resolve, config.CHECK_INTERVAL_MIN * 60 * 1000)
);
}
})();
- Randomized Delays: Add human-like pauses between actions.
await page.waitForTimeout(Math.random() * 5000 + 1000); // 1–6s delay
- Proxy Rotation: Use a pool of residential proxies to mask IPs.
- Mouse Movements: Simulate realistic mouse trajectories.
await page.mouse.move(100, 200); await page.mouse.click(100, 200); // Click instead of direct navigation
- Automated Retry:
- Close the browser, switch proxies, and retry.
- Manual Intervention (Fallback):
- Send a notification prompting the user to solve the CAPTCHA.
Test Case | Expected Outcome |
---|---|
Stealth Mode | No CAPTCHA detected for 24 hours. |
Proxy Rotation | IP changes between checks. |
Stock Detection | SMS sent when "Add to Cart" exists. |
CAPTCHA Fallback | Alert sent to user for manual solve. |
- Run via PM2 for background process:
pm2 start --interpreter=ts-node --name egg-monitor monitor.ts
- Use AWS EC2 or DigitalOcean with cron jobs.
- HTML Selector Updates: Adjust code if Amazon changes page structure.
- Proxy Health Checks: Monitor and replace blocked proxies.
Risk | Mitigation |
---|---|
IP Ban | Use high-quality residential proxies. |
Legal Issues | Check Amazon’s ToS; use sparingly. |
CAPTCHA Arms Race | Integrate CAPTCHA services as fallback. |
- Source code with TypeScript setup.
- Proxy configuration guide.
- SMS/email alert integration docs.
Timeline: 3–5 days (depending on proxy/notification setup).
Cost: ~$50/month (proxies + Twilio credits).