跳到正文
DEV Community· BasaltBrowser·· 8 小時前AI 評分50

如何測試瀏覽器指紋,並用 Playwright 建立隔離設定檔

Paste This Into Your Console and See How Unique Your Browser Really Is 🧬

AI 導讀

文章提供程式碼測試瀏覽器指紋,將 Canvas、WebGL 等裝置訊號組合成 16 個字元的 ID。文中指出,無痕模式或清除 Cookie 通常不會改變 ID,換瀏覽器或裝置則會改變。Playwright browser contexts 可設定不同語言、時區及畫面尺寸,但 Canvas、WebGL 和字體等深層訊號仍來自真實硬件;作者亦介紹 Basalt,稱其可在瀏覽器引擎層處理指紋。

正文

You cleared your cookies. You opened an incognito window. You feel anonymous.

Websites can still recognize you. They don't need cookies to do it: your browser gives away dozens of small details about your device, and together those details form a browser fingerprint.

Let's measure yours. It takes 30 seconds. 👇

🧪 Experiment #1: Get your fingerprint ID

Open DevTools (F12 or Cmd+Option+I), go to the Console tab, paste this code and press Enter:

(async () => {
  // 1. Canvas: the same drawing renders slightly differently on each GPU, driver and OS
  const canvas = document.createElement('canvas');
  const ctx = canvas.getContext('2d');
  ctx.textBaseline = 'top';
  ctx.font = '16px Arial';
  ctx.fillStyle = '#f60';
  ctx.fillRect(10, 10, 100, 30);
  ctx.fillStyle = '#069';
  ctx.fillText('Hello, fingerprint 👋', 4, 20);
  const canvasData = canvas.toDataURL();

  // 2. WebGL: your graphics card tells on you
  const gl = document.createElement('canvas').getContext('webgl');
  const dbg = gl && gl.getExtension('WEBGL_debug_renderer_info');
  const webgl = dbg
    ? `${gl.getParameter(dbg.UNMASKED_VENDOR_WEBGL)} | ${gl.getParameter(dbg.UNMASKED_RENDERER_WEBGL)}`
    : 'unavailable';

  // 3. Everything else the browser shares freely
  const signals = {
    userAgent: navigator.userAgent,
    languages: navigator.languages.join(', '),
    platform: navigator.platform,
    cpuCores: navigator.hardwareConcurrency,
    deviceMemoryGB: navigator.deviceMemory ?? 'n/a',
    screen: `${screen.width}x${screen.height} @${devicePixelRatio}x`,
    colorDepth: screen.colorDepth,
    timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
    touchPoints: navigator.maxTouchPoints,
    webgl,
  };

  const hash = async (str) => {
    const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(str));
    return [...new Uint8Array(buf)]
      .map((b) => b.toString(16).padStart(2, '0'))
      .join('')
      .slice(0, 16);
  };

  console.table(signals);
  console.log('🎨 Canvas hash:', await hash(canvasData));
  console.log('🧬 Your fingerprint ID:', await hash(JSON.stringify(signals) + canvasData));
})();

You'll get a table of signals and a 16-character fingerprint ID.

💬 Drop your fingerprint ID in the comments! If two of us get the same one, I'll be very surprised.

🕵️ Experiment #2: Try to escape

Now try to get a different ID:

  • [ ] Open an incognito / private window and run it again
  • [ ] Clear all cookies and run it again
  • [ ] Run it in a different browser (Chrome → Firefox)
  • [ ] Run it on your phone

What you'll probably find: incognito and clearing cookies change nothing. Your ID stays the same because none of these signals come from cookies. Switching browsers or devices does change it.

💬 Tell me in the comments: which checkbox actually changed your ID?

🤔 Why this works

None of these values identifies you on its own. Millions of people use Chrome on Windows. But combine them:

Signal Example Why it matters
Canvas render a3f9… Tiny GPU, driver and font differences change the pixels
WebGL renderer ANGLE (NVIDIA GeForce RTX 3060…) Names your actual graphics card
Timezone + language Europe/London, en-GB, ro Narrows down location and background
Screen + pixel ratio 2560x1440 @1.25x Less common than you'd think
CPU cores + memory 12, 8 Rounds out the device profile

Each signal cuts the crowd down further. Put a dozen of them together and you're often one in hundreds of thousands. This is called entropy, and fingerprinting scripts are built around it.

🧰 Experiment #3: Spin up isolated profiles with Playwright

Developers run into the opposite problem. When you test a website, you need sessions that look like different users: different locales, timezones and screen sizes, with no shared cookies.

Playwright's browser contexts do this out of the box:

// npm i playwright && npx playwright install chromium
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();

  const profiles = [
    { name: '🇩🇪 Berlin', locale: 'de-DE', timezoneId: 'Europe/Berlin', viewport: { width: 1366, height: 768 } },
    { name: '🇧🇷 São Paulo', locale: 'pt-BR', timezoneId: 'America/Sao_Paulo', viewport: { width: 1920, height: 1080 } },
    { name: '🇯🇵 Tokyo', locale: 'ja-JP', timezoneId: 'Asia/Tokyo', viewport: { width: 390, height: 844 }, isMobile: true },
  ];

  for (const { name, ...options } of profiles) {
    const context = await browser.newContext(options); // isolated cookies + storage
    const page = await context.newPage();

    const info = await page.evaluate(() => ({
      language: navigator.language,
      timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
      viewport: `${innerWidth}x${innerHeight}`,
      localTime: new Date().toLocaleString(),
    }));

    console.log(name, info);
    await context.close();
  }

  await browser.close();
})();

Run it with node profiles.js and you'll see three "users" with three different languages, clocks and screens, all from one machine.

⚠️ The catch

Look closer and these profiles still share a lot: the same canvas hash, the same WebGL renderer, the same fonts. Playwright changes the surface-level signals, but the deep ones come from your real hardware.

For quick QA that's usually fine. If you manage dozens of client accounts, or you're testing how a site behaves for genuinely different devices, you need each profile to be fully consistent and fully isolated.

That's the problem anti-detect browsers (also called multi-profile browsers) solve. Each profile gets its own complete fingerprint, its own proxy and its own storage. I've been using Basalt. It handles fingerprints at the browser-engine level, gives every profile its own CDP endpoint for Puppeteer and Playwright, and runs an AI agent on a local model, so nothing leaves your machine. It runs on Windows, macOS and Linux.

🧠 Quick quiz (answers below)

  1. Does incognito mode change your fingerprint?
  2. Which signal can reveal your graphics card model?
  3. Does a VPN alone make you unrecognizable?

👉 Click for answers

  1. No. Incognito only keeps cookies and history from being saved. Your device signals stay the same.
  2. WebGL, through the WEBGL_debug_renderer_info extension.
  3. No. A VPN changes your IP address, but your fingerprint stays the same. A mismatch, like a London timezone behind a Brazilian IP, can make you stand out more.

💬 Your turn

  • Post your fingerprint ID and the **one signal that surprised you most.
  • Have you ever needed isolated browser profiles for testing or work? What did you use?

If this was useful, drop a ❤️ and follow. Next up: **"How to detect a fingerprinting script on any website, in 5 minutes.

來源:DEV Community · dev.to