Stealth mode plugin for puppeteer-extra that applies various techniques to make detection of headless browsers harder.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Evasion techniques that mock Chrome-specific APIs to prevent detection through missing Chrome objects. These evasions simulate the presence of Chrome extension APIs that are typically available in regular Chrome browsers but missing in headless mode.
Mocks the chrome.app API to prevent detection through its absence.
// Evasion name: 'chrome.app'
// Simulates: chrome.app.isInstalled property and related functionalityThis evasion:
chrome.app object when it doesn't existchrome.app.isInstalled propertyDetection Method Prevented:
// This detection method will be fooled:
if (typeof chrome !== 'undefined' && chrome.app) {
// Assumes real browser
} else {
// Detects headless/automation
}Mocks the chrome.csi API for Chrome Site Isolation metrics.
// Evasion name: 'chrome.csi'
// Simulates: chrome.csi() function and performance metricsThis evasion:
chrome.csi() functionDetection Method Prevented:
// This detection method will be fooled:
try {
const csi = chrome.csi();
if (csi && csi.pageT) {
// Assumes real Chrome browser
}
} catch (e) {
// Detects missing Chrome CSI API
}Mocks the deprecated chrome.loadTimes API for backward compatibility.
// Evasion name: 'chrome.loadTimes'
// Simulates: chrome.loadTimes() function with realistic timing dataThis evasion:
chrome.loadTimes() functionDetection Method Prevented:
// This detection method will be fooled:
if (chrome && chrome.loadTimes) {
const loadTimes = chrome.loadTimes();
if (loadTimes.requestTime && loadTimes.finishDocumentLoadTime) {
// Assumes real Chrome with load times API
}
}Mocks the chrome.runtime API that's normally available in Chrome extensions.
// Evasion name: 'chrome.runtime'
// Simulates: chrome.runtime object with extension-like propertiesThis evasion:
chrome.runtime objectchrome.runtime.sendMessage functionchrome.runtime.connect and related methodsDetection Method Prevented:
// This detection method will be fooled:
if (chrome && chrome.runtime && chrome.runtime.sendMessage) {
try {
chrome.runtime.sendMessage('test');
// Assumes Chrome extension environment
} catch (e) {
// Would detect fake/missing runtime API
}
}Usage Examples:
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
// Enable only Chrome API evasions
const chromeOnlyStealth = StealthPlugin({
enabledEvasions: new Set([
'chrome.app',
'chrome.csi',
'chrome.loadTimes',
'chrome.runtime'
])
});
puppeteer.use(chromeOnlyStealth);
const browser = await puppeteer.launch();
const page = await browser.newPage();
// These Chrome APIs will now be available and functional
await page.evaluate(() => {
console.log(chrome.app.isInstalled); // Works
console.log(chrome.csi()); // Returns timing data
console.log(chrome.loadTimes()); // Returns load timing
chrome.runtime.sendMessage('test'); // Functions without error
});The Chrome API evasions use static data files to provide realistic responses:
staticData.json for realistic extension-like dataEach Chrome API evasion:
These evasions:
Install with Tessl CLI
npx tessl i tessl/npm-puppeteer-extra-plugin-stealth