All-in-one Puppeteer-based browser automation manager with 25+ battle-tested utilities: stealth browsing, smart tab tracking, dialogs, clipboard, console + network monitoring, downloads, performance metrics, mobile emulation, geolocation, and more.
npm install apna-browserRequires Node.js 18 or newer. Puppeteer is installed automatically.
import ApnaBrowser from 'apna-browser';
const browser = new ApnaBrowser();
await browser.launchBrowser({
stealth: true,
ignoreSSLErrors: true,
});
await browser.openNewTab('https://www.google.com');
await browser.typeText('textarea[name="q"]', 'Apna Browser automation');
await browser.click('input[name="btnK"]');
await browser.wait(5000);
await browser.takeScreenshot('google-search.png');
await browser.closeBrowser();- Stealth-ready launch options that bypass common bot detections
- Automatic tab tracking and tab management helpers
- Rich interaction helpers (typing, clicking, drag-and-drop, hover, iframes, clipboard)
- Built-in console log and network request capture
- Performance, device emulation, geolocation and download helpers
- Sensible Hindi-friendly logging out of the box
- Installation
- Quick Start
- Highlights
- Advanced Usage
- Complete Usage Reference
- API Overview
- Example Script
- Support & Feedback
- License
import ApnaBrowser from 'apna-browser';
const browser = new ApnaBrowser();
await browser.launchBrowser({
stealth: true,
ignoreSSLErrors: true,
autoDetect: true,
});
await browser.openNewTab('https://news.ycombinator.com');
await browser.openNewTab('https://github.com/alsocoders');
await browser.switchToTab(0);
await browser.reload();
await browser.nextTab();
await browser.navigateTo('https://alsocoder.com');browser.enableAutoDialogHandler({
alert: 'accept',
confirm: 'accept',
prompt: 'accept',
promptText: 'Namaste!',
});
await browser.enableNetworkMonitoring();
browser.setupConsoleCapture(browser.page);
await browser.click('#trigger-dialog');
const consoleErrors = browser.getConsoleErrors();
const recentRequests = browser.getNetworkRequests({ limit: 5 });await browser.typeText('#email', 'user@alsocoder.com');
await browser.typeText('#password', 'super-secret');
await browser.click('#login');
await browser.waitForNavigation();
await browser.selectText('.profile-name');
const copiedName = await browser.copySelectedText();
const linkCount = await browser.countElements('a');
const isVisible = await browser.isElementVisible('#dashboard');await browser.getPerformanceMetrics();
browser.printPerformanceMetrics();
await browser.takeScreenshot('dashboard.png');
await browser.generatePDF('dashboard.pdf');
await browser.enableDownloads('./downloads');
await browser.click('#download-report');
await browser.waitForDownload(5000);await browser.setViewport(390, 844);
await browser.emulateMobile('iPhone 13 Pro');
await browser.grantGeolocationPermission();
await browser.setGeolocation(28.6139, 77.2090); // New Delhi
await browser.reload();await browser.clickInFrame('#ad-frame', 'button.close');
await browser.dragAndDrop('#item-1', '#dropzone');
await browser.pressKeyCombination(['Control', 'Shift', 'KeyT']);
await browser.ctrlF();
await browser.escape();await browser.closeAllTabs();
await browser.closeBrowser();Each snippet assumes you created an instance via:
import ApnaBrowser from 'apna-browser';
const browser = new ApnaBrowser();await browser.launchBrowser({ headless: false, stealth: true });
await browser.enableAutoDetection();
await browser.refreshTabs();
await browser.closeBrowser();await browser.openNewTab('https://example.com');
await browser.switchToTab(0);
await browser.duplicateCurrentTab();
await browser.closeCurrentTab();
await browser.closeAllTabs();
const tabs = await browser.getAllTabs();
const { page: incognitoPage, context } = await browser.openIncognitoTab('https://alsocoder.com');
await context.close();await browser.navigateTo('https://alsocoder.com/blog');
await browser.waitForNavigation();
await browser.goBack();
await browser.goForward();
await browser.reload();
await browser.wait(1500);
await browser.waitForSelector('#hero');await browser.handleAlert(true);
await browser.handleConfirm(false);
await browser.handlePrompt('Namaste', true);
browser.enableAutoDialogHandler({
alert: 'accept',
confirm: 'dismiss',
prompt: 'accept',
promptText: 'नमस्ते',
});
browser.disableAutoDialogHandler();await browser.typeText('#search', 'Apna Browser rocks!');
await browser.click('.submit');
await browser.doubleClick('.card');
await browser.rightClick('.card');
await browser.hover('.menu');
await browser.hoverAndClick('.menu', '.menu-item:last-child');
await browser.dragAndDrop('#item-1', '#drop-target');await browser.selectText('article h1');
const headline = await browser.copySelectedText();
await browser.selectAll();
await browser.copy();
await browser.cut();
await browser.paste();
await browser.pasteIntoField('#notes', 'Copied content');
await browser.selectOption('#country', 'IN');
await browser.setCheckbox('#terms', true);
await browser.uploadFile('input[type="file"]', './assets/resume.pdf');
await browser.focus('#comments');const exists = await browser.elementExists('.ticket');
const titleText = await browser.getText('.title');
const href = await browser.getAttribute('.cta', 'href');
const count = await browser.countElements('a');
const allHeadings = await browser.getAllText('h2');
const visible = await browser.isElementVisible('#status');await browser.evaluate(() => window.dispatchEvent(new Event('resize')));
await browser.scrollTo(0, 500);
await browser.scrollToBottom();
await browser.scrollToElement('#footer');await browser.takeScreenshot('full-page.png');
await browser.takeScreenshot('viewport.png', { fullPage: false });
await browser.generatePDF('report.pdf', { format: 'A4', printBackground: true });browser.setupConsoleCapture(browser.page);
await browser.enableNetworkMonitoring();
await browser.enableRequestBlocking(['image', 'font']);
browser.printConsoleLogs();
const errors = browser.getConsoleErrors();
const warnings = browser.getConsoleWarnings();
const requests = browser.getNetworkRequests({ type: 'xhr', limit: 10 });
browser.clearConsoleLogs();
browser.clearNetworkRequests();const metrics = await browser.getPerformanceMetrics();
console.log(metrics.pageLoadTime);
browser.printPerformanceMetrics();const cookies = await browser.getCookies();
await browser.setCookie({ name: 'user', value: 'also-coder' });
await browser.clearCookies();
const localStorage = await browser.getLocalStorage();
await browser.clearLocalStorage();await browser.enableDownloads('./tmp/downloads');
await browser.click('#download');
await browser.waitForDownload(10000);await browser.setViewport(1280, 800);
await browser.setUserAgent('Mozilla/5.0 (...custom UA...)');
await browser.emulateMobile('iPhone 13 Pro');
const availableDevices = browser.getAvailableDevices();
await browser.grantGeolocationPermission();
await browser.setGeolocation(12.9716, 77.5946); // Bengaluruawait browser.pressKey('Enter');
await browser.pressKeyCombination(['Control', 'Shift', 'KeyT']);
await browser.ctrlS();
await browser.ctrlF();
await browser.ctrlW();
await browser.ctrlT();
await browser.ctrlShiftT();
await browser.escape();
await browser.enter();
await browser.tab();await browser.switchToFrame('iframe#payment');
await browser.currentFrame.type('#card', '4242424242424242');
await browser.switchToMainFrame();
await browser.clickInFrame('iframe#ad', 'button.close');const dimensions = await browser.getPageDimensions();
console.log(dimensions.width, dimensions.height);
const url = await browser.getURL();
const title = await browser.getTitle();| Category | Key Methods |
|---|---|
| Browser | launchBrowser, closeBrowser, enableAutoDetection, refreshTabs |
| Tabs | openNewTab, switchToTab, nextTab, closeTab, duplicateCurrentTab |
| Navigation | navigateTo, reload, goBack, goForward, waitForNavigation |
| Interactions | typeText, click, doubleClick, hover, dragAndDrop, pressKeyCombination |
| Clipboard | selectText, copySelectedText, pasteIntoField |
| Media | takeScreenshot, generatePDF |
| Monitoring | setupConsoleCapture, getConsoleLogs, enableNetworkMonitoring |
| Utilities | getPerformanceMetrics, setViewport, emulateMobile, setGeolocation, enableDownloads |
See lib/ApnaBrowser.js for the full API documentation via inline comments.
The following script demonstrates a full-featured flow you can copy into your project:
import ApnaBrowser from 'apna-browser';
async function exampleDemo() {
const manager = new ApnaBrowser();
try {
await manager.launchBrowser({ stealth: true, ignoreSSLErrors: true });
manager.enableAutoDialogHandler({ alert: 'accept', confirm: 'accept' });
await manager.openNewTab('https://www.google.com');
await manager.wait(2000);
await manager.openNewTab('https://www.github.com');
await manager.wait(2000);
await manager.openNewTab('https://www.youtube.com');
await manager.wait(2000);
await manager.switchToTab(0);
await manager.typeText('textarea[name="q"]', 'Browser automation', { delay: 100 });
await manager.wait(1000);
await manager.click('input[name="btnK"]');
await manager.wait(5000);
try {
await manager.selectText('h3');
const copiedText = await manager.copySelectedText();
console.log(`Copied: ${copiedText.substring(0, 50)}...`);
} catch {
console.log('Copy demo skipped');
}
await manager.getPerformanceMetrics();
manager.printPerformanceMetrics();
const linkCount = await manager.countElements('a');
console.log(`Total links: ${linkCount}`);
await manager.takeScreenshot('demo-screenshot.png');
} catch (error) {
console.error('Error:', error.message);
await manager.takeScreenshot('error.png');
} finally {
await manager.closeBrowser();
}
}
exampleDemo();- Report bugs or feature requests at github.com/alsocoders/apna-browser/issues
- Explore examples, updates, and tips on alsocoder.com
- Share feedback via discussions or pull requests—community contributions are welcome!
MIT © Also Coder · https://alsocoder.com
Use the package freely in your projects, but do not redistribute modified versions under the same name.