infosimples / detect-headless Goto Github PK
View Code? Open in Web Editor NEWAccess https://infosimples.github.io/detect-headless to run several headless detection tests against your browser.
License: MIT License
Access https://infosimples.github.io/detect-headless to run several headless detection tests against your browser.
License: MIT License
When in Chrome (headful) you right-click on a link and "open in a new tab" then page loads in background (in new tab) and the window.outerHeight
/ window.outerWidth
are zero until the tab is activated.
Isn't there a standard answer to this question?
I passed almost all the tests.
But Plugins Prototype Test is an exception.
Could you please help me?
const puppeteer = require('puppeteer');
async function test() {
var browser = await puppeteer.launch({
ignoreDefaultArgs: ['--enable-automation'],
});
var page = await pageInit(browser);
// var page = await browser.newPage();
page.on('dialog', async (age) => {
console.log(age.type());
await page.waitFor(3e2);
console.log(age.message());
await age.dismiss()
});
await page.goto('https://infosimples.github.io/detect-headless/');
await page.waitFor(3e2);
await page.mouse.move(50, 50, { steps: 50 });
await page.screenshot({
path: './' + Date.now() + '.png',
fullPage: true,
});
// await browser.close();
console.log('end');
}
async function pageInit(browser) {
var page, pages = await browser.pages();
if (pages.length > 0) {
page = pages[0];
} else {
page = await browser.newPage();
}
await page.setExtraHTTPHeaders({
'Accept-Language': 'zh-CN,zh;q=0.9'
});
//User-Agent Test
await page.setUserAgent('Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36');
await page.evaluateOnNewDocument(() => {
//Webdriver Test
Object.defineProperty(navigator, 'webdriver', {
get: () => false,
});
//connection.rtt Test
Object.defineProperty(navigator.connection, 'rtt', {
get: () => 50,
});
//Plugins Length Test
Object.defineProperty(navigator, 'plugins', {
get: () => {
var ChromiumPDFPlugin = {};
ChromiumPDFPlugin.__proto__ = PluginArray.prototype;
return [ChromiumPDFPlugin];
},
});
});
//Chrome Test
const trueChromeObject = { "app": { "isInstalled": false }, "webstore": { "onInstallStageChanged": {}, "onDownloadProgress": {} }, "runtime": { "PlatformOs": { "MAC": "mac", "WIN": "win", "ANDROID": "android", "CROS": "cros", "LINUX": "linux", "OPENBSD": "openbsd" }, "PlatformArch": { "ARM": "arm", "X86_32": "x86-32", "X86_64": "x86-64" }, "PlatformNaclArch": { "ARM": "arm", "X86_32": "x86-32", "X86_64": "x86-64" }, "RequestUpdateCheckStatus": { "THROTTLED": "throttled", "NO_UPDATE": "no_update", "UPDATE_AVAILABLE": "update_available" }, "OnInstalledReason": { "INSTALL": "install", "UPDATE": "update", "CHROME_UPDATE": "chrome_update", "SHARED_MODULE_UPDATE": "shared_module_update" }, "OnRestartRequiredReason": { "APP_UPDATE": "app_update", "OS_UPDATE": "os_update", "PERIODIC": "periodic" } } };
await page.evaluateOnNewDocument(() => {
chrome = { "app": { "isInstalled": false }, "webstore": { "onInstallStageChanged": {}, "onDownloadProgress": {} }, "runtime": { "PlatformOs": { "MAC": "mac", "WIN": "win", "ANDROID": "android", "CROS": "cros", "LINUX": "linux", "OPENBSD": "openbsd" }, "PlatformArch": { "ARM": "arm", "X86_32": "x86-32", "X86_64": "x86-64" }, "PlatformNaclArch": { "ARM": "arm", "X86_32": "x86-32", "X86_64": "x86-64" }, "RequestUpdateCheckStatus": { "THROTTLED": "throttled", "NO_UPDATE": "no_update", "UPDATE_AVAILABLE": "update_available" }, "OnInstalledReason": { "INSTALL": "install", "UPDATE": "update", "CHROME_UPDATE": "chrome_update", "SHARED_MODULE_UPDATE": "shared_module_update" }, "OnRestartRequiredReason": { "APP_UPDATE": "app_update", "OS_UPDATE": "os_update", "PERIODIC": "periodic" } } };
window.chrome = { "app": { "isInstalled": false }, "webstore": { "onInstallStageChanged": {}, "onDownloadProgress": {} }, "runtime": { "PlatformOs": { "MAC": "mac", "WIN": "win", "ANDROID": "android", "CROS": "cros", "LINUX": "linux", "OPENBSD": "openbsd" }, "PlatformArch": { "ARM": "arm", "X86_32": "x86-32", "X86_64": "x86-64" }, "PlatformNaclArch": { "ARM": "arm", "X86_32": "x86-32", "X86_64": "x86-64" }, "RequestUpdateCheckStatus": { "THROTTLED": "throttled", "NO_UPDATE": "no_update", "UPDATE_AVAILABLE": "update_available" }, "OnInstalledReason": { "INSTALL": "install", "UPDATE": "update", "CHROME_UPDATE": "chrome_update", "SHARED_MODULE_UPDATE": "shared_module_update" }, "OnRestartRequiredReason": { "APP_UPDATE": "app_update", "OS_UPDATE": "os_update", "PERIODIC": "periodic" } } };
window.navigator.chrome = { "app": { "isInstalled": false }, "webstore": { "onInstallStageChanged": {}, "onDownloadProgress": {} }, "runtime": { "PlatformOs": { "MAC": "mac", "WIN": "win", "ANDROID": "android", "CROS": "cros", "LINUX": "linux", "OPENBSD": "openbsd" }, "PlatformArch": { "ARM": "arm", "X86_32": "x86-32", "X86_64": "x86-64" }, "PlatformNaclArch": { "ARM": "arm", "X86_32": "x86-32", "X86_64": "x86-64" }, "RequestUpdateCheckStatus": { "THROTTLED": "throttled", "NO_UPDATE": "no_update", "UPDATE_AVAILABLE": "update_available" }, "OnInstalledReason": { "INSTALL": "install", "UPDATE": "update", "CHROME_UPDATE": "chrome_update", "SHARED_MODULE_UPDATE": "shared_module_update" }, "OnRestartRequiredReason": { "APP_UPDATE": "app_update", "OS_UPDATE": "os_update", "PERIODIC": "periodic" } } };
});
//Permissions Test
await page.evaluateOnNewDocument(() => {
const originalQuery = window.navigator.permissions.query;
return window.navigator.permissions.query = (parameters) => (
parameters.name === 'notifications' ? Promise.resolve({ state: Notification.permission }) :
originalQuery(parameters)
);
});
//Languages Test
await page.evaluateOnNewDocument(() => {
Object.defineProperty(navigator, 'languages', {
get: () => ['zh-CN'],
});
});
return page;
}
test();
We have observed that 2%-3% Edge traffic that has navigator.connection.rtt
set to 0. It's much higher than other headless signals. So I wonder if there can possibly be any false positives for the rule: navigator.connection.rtt == 0 on Edge browsers?
Actually I searched around the Internet, but didn't find a strong evidence to prove that navigator.connection.rtt == 0 indicates a headless bot, except here. Any answers would be appreciated. Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.