Auditing Browser Fingerprint Consistency in Node.js with Playwright and CI Gates
Overriding a User-Agent header in Playwright takes one option, yet plenty of scrapers still hit challenge walls after changing it. The mismatch usually sits one layer deeper: the HTTP header and navigator.userAgent report one browser, while TLS ClientHello extensions, HTTP/2 SETTINGS frames, HTTP sec-ch-ua headers, and navigator.userAgentData still describe another.
This developer guide implements a dependency-light Node.js ES module probe and cross-layer auditor using Playwright and https://tls.peet.ws/api/all, verifies it on a real headless Chrome 158 baseline versus a spoofed Firefox 140 page, and shows how to wire --fail-on-warn into GitHub Actions.
Setup
Use Node 18 or newer with "type": "module" in package.json:
mkdir fingerprint-audit && cd fingerprint-audit
npm init -y
npm pkg set type=module
npm i playwright
npx playwright install chromium
Capturing TLS, HTTP/2, Client Hints, and JS signals in Node.js
Create probe.mjs. Call page.goto() inside the browser context to fetch https://tls.peet.ws/api/all. Do not swap it for page.request.get(), because Playwright’s API request context runs on a separate HTTP client and hides Chromium’s TLS handshake and HTTP/2 frames.
import { writeFileSync } from 'node:fs';
import { parseArgs } from 'node:util';
import { chromium } from 'playwright';
const URL = 'https://tls.peet.ws/api/all';
async function capture(userAgent) {
const browser = await chromium.launch({ headless: true });
try {
const page = userAgent ? await browser.newPage({ userAgent }) : await browser.newPage();
const response = await page.goto(URL, { waitUntil: 'domcontentloaded' });
if (!response || !response.ok()) {
throw new Error(`Unexpected response: ${response?.status()}`);
}
const data = await response.json();
const browserData = await page.evaluate(() => {
const uaData = navigator.userAgentData;
return {
user_agent: navigator.userAgent,
platform: navigator.platform,
language: navigator.language,
languages: [...navigator.languages],
webdriver: navigator.webdriver,
user_agent_data: uaData
? {
brands: uaData.brands,
mobile: uaData.mobile,
platform: uaData.platform,
}
: null,
};
});
const tls = data.tls || {};
const http2 = data.http2 || {};
const sentFrames = http2.sent_frames || [];
const settings = sentFrames.find((frame) => frame.frame_type === 'SETTINGS')?.settings || [];
const clientHints = {};
const headersFrame = sentFrames.find((frame) => frame.frame_type === 'HEADERS');
if (headersFrame) {
for (const line of headersFrame.headers || []) {
const sep = line.indexOf(':');
if (sep === -1) continue;
const name = line.slice(0, sep).toLowerCase();
const value = line.slice(sep + 1).trim();
if (name === 'sec-ch-ua' || name === 'sec-ch-ua-mobile' || name === 'sec-ch-ua-platform') {
clientHints[name] = value;
}
}
}
return {
network: {
user_agent: data.user_agent,
client_hints: clientHints,
http_version: data.http_version,
tls: {
ja3_hash: tls.ja3_hash,
ja4: tls.ja4,
},
http2: {
akamai_fingerprint: http2.akamai_fingerprint,
settings,
},
},
browser: browserData,
};
} finally {
await browser.close();
}
}
const { values } = parseArgs({
options: {
'user-agent': { type: 'string' },
out: { type: 'string', default: 'fingerprint.json' },
},
});
const fingerprint = await capture(values['user-agent']);
writeFileSync(values.out, JSON.stringify(fingerprint, null, 2) + '\n', 'utf8');
console.log(`Saved ${values.out}`);
Run it once to save your reference baseline:
node probe.mjs --out baseline.json
On headless Chrome 158 running on macOS, baseline.json recorded:
{
"network": {
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/158.0.0.0 Safari/537.36",
"client_hints": {
"sec-ch-ua": "\"Chromium\";v=\"158\", \"Not.A/Brand\";v=\"24\", \"Google Chrome\";v=\"158\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\""
},
"http_version": "h2",
"tls": {
"ja3_hash": "4d6c7883654b2fd351caf9d95ac221d4",
"ja4": "t13d1517h2_8daaf6152771_cb7bf5808d99"
},
"http2": {
"akamai_fingerprint": "1:65536;2:0;4:6291456;6:262144|15663105|0|m,a,s,p",
"settings": [
"HEADER_TABLE_SIZE = 65536",
"ENABLE_PUSH = 0",
"INITIAL_WINDOW_SIZE = 6291456",
"MAX_HEADER_LIST_SIZE = 262144"
]
}
},
"browser": {
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/158.0.0.0 Safari/537.36",
"platform": "MacIntel",
"language": "en-US",
"languages": ["en-US", "en"],
"webdriver": true,
"user_agent_data": {
"brands": [
{ "brand": "Chromium", "version": "158" },
{ "brand": "Not.A/Brand", "version": "24" },
{ "brand": "Google Chrome", "version": "158" }
],
"mobile": false,
"platform": "macOS"
}
}
}
Writing the cross-layer auditor (audit.mjs)
The auditor normalizes platform identifiers (MacIntel and macOS both map to macOS), strips Chromium’s GREASE brand (Not.A/Brand) before comparing HTTP and JS Client Hints, and separates cross-layer contradictions (WARN) from routine network drift (INFO). It skips ja3_hash because Chromium shuffles TLS extensions between launches: on our machine, two back-to-back runs of identical Chrome 158 produced 4d6c7883654b2fd351caf9d95ac221d4 and 6db4e10a3cb82dddbf06bc21a17486ac, while ja4 remained fixed at t13d1517h2_8daaf6152771_cb7bf5808d99. Create audit.mjs:
import { readFileSync } from 'node:fs';
import { parseArgs } from 'node:util';
function browserFamily(userAgent = '') {
if (userAgent.includes('Firefox/')) return 'Firefox';
if (['HeadlessChrome/', 'Chrome/', 'Chromium/', 'Edg/'].some((name) => userAgent.includes(name))) {
return 'Chromium';
}
return null;
}
function platformName(value = '') {
const v = (value || '').toLowerCase();
if (v.includes('windows') || v.startsWith('win')) return 'Windows';
if (v.includes('android')) return 'Android';
if (v.includes('iphone') || v.includes('ipad') || v.includes('ios')) return 'iOS';
if (v.includes('mac')) return 'macOS';
if (v.includes('linux') || v.includes('x11')) return 'Linux';
return null;
}
function relevantBrands(pairs) {
const known = new Set(['Chromium', 'HeadlessChrome', 'Google Chrome', 'Microsoft Edge']);
return new Set(
pairs
.filter(([name]) => known.has(name))
.map(([name, version]) => `${name}:${version}`),
);
}
function setsEqual(a, b) {
if (a.size !== b.size) return false;
for (const item of a) {
if (!b.has(item)) return false;
}
return true;
}
export function audit(current, baseline = null) {
const network = current.network || {};
const browser = current.browser || {};
const hints = browser.user_agent_data || {};
const ua = network.user_agent || '';
const jsUa = browser.user_agent || '';
const results = [];
const record = (level, message) => results.push([level, message]);
if (ua && jsUa) {
const matches = ua === jsUa;
record(
matches ? 'PASS' : 'WARN',
matches ? 'HTTP and JavaScript User-Agents match' : 'HTTP and JavaScript User-Agents differ',
);
} else {
record('INFO', 'User-Agent missing from one of the layers');
}
const platforms = [
platformName(ua),
platformName(browser.platform),
platformName(hints.platform),
].filter(Boolean);
if (platforms.length >= 2) {
const matches = new Set(platforms).size === 1;
record(
matches ? 'PASS' : 'WARN',
matches ? 'Reported platforms agree' : `Platform mismatch: ${platforms.join(', ')}`,
);
}
const brands = hints.brands || [];
const hasChromiumBrand = brands.some(
(item) => (item.brand || '').includes('Chromium') || (item.brand || '').includes('Chrome'),
);
const family = browserFamily(ua);
if (family === 'Firefox' && hasChromiumBrand) {
record('WARN', 'User-Agent claims Firefox, but Client Hints identify Chromium');
} else if (family === 'Chromium' && hasChromiumBrand) {
record('PASS', 'User-Agent family agrees with Client Hints');
} else if (Object.keys(hints).length > 0) {
record('INFO', 'Browser family could not be checked reliably');
}
if (family === 'Chromium') {
const match = ua.match(/(?:HeadlessChrome|Chrome|Chromium|Edg)\/(\d+)/);
const chromiumVersions = new Set(
brands
.filter((item) => ['Chromium', 'HeadlessChrome', 'Google Chrome'].includes(item.brand))
.map((item) => item.version),
);
if (match && chromiumVersions.size > 0) {
const major = match[1];
const matches = chromiumVersions.has(major);
record(
matches ? 'PASS' : 'WARN',
`Chromium major version ${matches ? 'matches' : 'differs from'} Client Hints (${major})`,
);
}
}
const httpHints = network.client_hints || {};
if (Object.keys(httpHints).length === 0 || Object.keys(hints).length === 0) {
record('INFO', 'HTTP or JavaScript Client Hints unavailable');
} else {
const httpPlatform = httpHints['sec-ch-ua-platform'];
if (httpPlatform !== undefined && hints.platform !== undefined) {
const matches = httpPlatform.replace(/^"|"$/g, '') === hints.platform;
record(
matches ? 'PASS' : 'WARN',
matches
? 'HTTP and JavaScript Client Hint platforms match'
: 'HTTP and JavaScript Client Hint platforms differ',
);
}
const httpMobile = httpHints['sec-ch-ua-mobile'];
if ((httpMobile === '?0' || httpMobile === '?1') && typeof hints.mobile === 'boolean') {
const matches = (httpMobile === '?1') === hints.mobile;
record(
matches ? 'PASS' : 'WARN',
matches
? 'HTTP and JavaScript mobile indicators match'
: 'HTTP and JavaScript mobile indicators differ',
);
}
const httpUa = httpHints['sec-ch-ua'];
if (httpUa) {
const httpPairs = [...httpUa.matchAll(/"([^"]+)";v="([^"]+)"/g)].map((m) => [m[1], m[2]]);
const jsPairs = (hints.brands || []).map((item) => [item.brand, item.version]);
const httpBrands = relevantBrands(httpPairs);
const jsBrands = relevantBrands(jsPairs);
if (httpBrands.size > 0 && jsBrands.size > 0) {
const matches = setsEqual(httpBrands, jsBrands);
record(
matches ? 'PASS' : 'WARN',
matches
? 'HTTP and JavaScript browser brands match'
: 'HTTP and JavaScript browser brands differ',
);
}
}
}
const http2 = network.http2 || {};
if (network.http_version === 'h2') {
if (http2.akamai_fingerprint && (http2.settings || []).length > 0) {
record('PASS', 'HTTP/2 negotiated and fingerprint details captured');
} else {
record('INFO', 'HTTP/2 negotiated, but some diagnostic fields are missing');
}
}
if (network.tls?.ja4) {
record('INFO', 'JA4 captured; browser family cannot be inferred from it alone');
}
if (browser.webdriver === true) {
record('INFO', 'Browser reports automation via navigator.webdriver');
}
if (baseline) {
const baseNetwork = baseline.network || {};
const baseFamily = browserFamily(baseNetwork.user_agent || '');
if (baseFamily && family && baseFamily !== family) {
const ja4 = network.tls?.ja4;
const h2 = http2.akamai_fingerprint;
const tlsSame = Boolean(ja4) && ja4 === baseNetwork.tls?.ja4;
const h2Same = Boolean(h2) && h2 === baseNetwork.http2?.akamai_fingerprint;
if (tlsSame && h2Same) {
record(
'WARN',
`User-Agent changed from ${baseFamily} to ${family}, while JA4 and HTTP/2 fingerprints still match the ${baseFamily} baseline`,
);
} else {
record('INFO', 'Browser family changed, but network fingerprints do not both match the baseline');
}
}
const comparisons = [
['JA4', network.tls?.ja4, baseNetwork.tls?.ja4],
['HTTP/2 fingerprint', http2.akamai_fingerprint, baseNetwork.http2?.akamai_fingerprint],
];
for (const [name, currentValue, oldValue] of comparisons) {
if (currentValue && oldValue && currentValue !== oldValue) {
record('INFO', `${name} changed from baseline`);
}
}
}
for (const [level, message] of results) {
console.log(`[${level}] ${message}`);
}
const warnings = results.filter(([level]) => level === 'WARN').length;
console.log(`\nWarnings: ${warnings}`);
return warnings;
}
const { values } = parseArgs({
options: {
input: { type: 'string', default: 'fingerprint.json' },
baseline: { type: 'string' },
'fail-on-warn': { type: 'boolean', default: false },
},
});
const current = JSON.parse(readFileSync(values.input, 'utf8'));
const baseline = values.baseline ? JSON.parse(readFileSync(values.baseline, 'utf8')) : null;
const warningCount = audit(current, baseline);
if (values['fail-on-warn'] && warningCount > 0) {
process.exit(1);
}
Catching a Firefox User-Agent override on Chromium
Test what happens when newPage({ userAgent }) passes a Firefox 140 User-Agent into Chrome 158:
node probe.mjs \
--user-agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:140.0) Gecko/20100101 Firefox/140.0" \
--out spoofed-firefox.json
node audit.mjs --input spoofed-firefox.json --baseline baseline.json --fail-on-warn
Output:
[PASS] HTTP and JavaScript User-Agents match
[PASS] Reported platforms agree
[WARN] User-Agent claims Firefox, but Client Hints identify Chromium
[PASS] HTTP and JavaScript Client Hint platforms match
[PASS] HTTP and JavaScript mobile indicators match
[PASS] HTTP and JavaScript browser brands match
[PASS] HTTP/2 negotiated and fingerprint details captured
[INFO] JA4 captured; browser family cannot be inferred from it alone
[INFO] Browser reports automation via navigator.webdriver
[WARN] User-Agent changed from Chromium to Firefox, while JA4 and HTTP/2 fingerprints still match the Chromium baseline
Warnings: 2
The process exits with code 1. Even though both User-Agent strings matched Firefox 140, HTTP sec-ch-ua, navigator.userAgentData, JA4 (t13d1517h2_8daaf6152771_cb7bf5808d99), and the HTTP/2 Akamai string (1:65536;2:0;4:6291456;6:262144|15663105|0|m,a,s,p) all stayed on Chrome 158. Running curl with Chrome’s User-Agent showed the inverse leak: curl generated ja4: t13d497h2_0d8feac7bc37_7395dae3b2f3 and HTTP/2 settings 3:100;4:10485760;2:0|1048510465|0|m,s,a,p.
Wiring --fail-on-warn into GitHub Actions
Pin package-lock.json and store separate baselines per runner OS and launch mode. Run the audit in CI whenever Playwright or proxy settings change:
name: Fingerprint consistency check
on:
pull_request:
paths:
- "package-lock.json"
- "src/browser/**"
jobs:
fingerprint-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
- run: npm ci
- run: npx playwright install --with-deps chromium
- run: node probe.mjs --out current.json
- run: node audit.mjs --input current.json --baseline baselines/linux-headless.json --fail-on-warn
Because JA4 changed from baseline and HTTP/2 fingerprint changed from baseline emit [INFO], routine browser upgrades will notify you without failing the workflow, while any cross-layer identity mismatch exits 1.
Offloading high-friction targets
For websites you scrape rarely or social platforms that pair TLS/HTTP/2 checks with aggressive IP reputation and request signing, keeping Playwright binaries, baselines, and residential proxies synchronized takes more work than extracting the fields you need. For TikTok or X/Twitter pipelines in Node.js, you can call hosted actors through apify-client instead:
import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('novi/tiktok-scraper-ultimate').call({
searchQueries: ['browser fingerprinting'],
resultsPerPage: 20,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(`Fetched ${items.length} rows`);
Both Ultimate TikTok Scraper and X.com Twitter API Scraper handle transport and rotation server-side, and Apify provides monthly free credit if you want to benchmark one against your own Playwright fleet.