Этот перевод создан машиной и ожидает проверки.Переключиться на английский
Обзор продуктаЗапросить демонстрацию

Guide: BrowserX

Check your consent mode from a leased browser

The Noxtica documentation describes a release check for the consent mode: open the live page with the banner unanswered and confirm that only the core script and one token request run. This guide automates that check with a clean Chromium that BrowserX leases and your own Playwright script drives.

Not a Noxtica product · Tool: BrowserX

Before you start

  • BrowserX built from source on a machine with Chromium installed. The doctor command checks that the machine can run browsers.
  • A Playwright script, or any client that speaks the Chrome DevTools Protocol.
  • A staging page you own that carries the Noxtica core tag with the staging domain's site key.
  • The consent mode you expect for that domain, for example api.
  • A worker configuration that lets the worker reach your staging host. A host on a private address needs its range in egress.allow_cidrs.

Written for sites you own. Commands come from each project's own documentation; check it before you rely on a flag.

Steps

  1. Start a BrowserX worker

    Check the machine and create an API key. The key is printed once, together with the configuration snippet that holds its digest. Also create the snapshot key, because the example configuration refers to it even for an ephemeral session. Copy the example configuration, replace its API-key entry with the printed snippet, check the file and start the worker on the loopback interface.

    Shell
    browserx doctor
    browserx keys new dev                                    # prints the key once, with the [[auth.api_keys]] snippet
    browserx snapshot-key new ./.browserx-keys/snapshot.key  # the example configuration names this file
    cp examples/browserx.toml browserx.toml                  # paste the printed snippet over its [[auth.api_keys]]
    browserx config check browserx.toml
    browserx serve --config browserx.toml
  2. Lease an ephemeral browser

    Create a session with persistence ephemeral, with the command line or a POST to the sessions endpoint. An ephemeral session keeps nothing after it ends, which is what a consent check needs. The response holds a session object with its identifier and generation, a controller token and the DevTools address. That address contains the token, so treat it as a secret and keep it out of logs.

    Shell
    export BROWSERX_SERVER=http://127.0.0.1:7690
    export BROWSERX_API_KEY=<the key printed by keys new>
    browserx session create --persistence ephemeral   # JSON: session, token, cdp_url
  3. Attach, listen early and open the page

    Connect your script to the leased browser over the DevTools address and use the browser's first context. Register the collected-event listener with an init script on that context, so it runs before any page script, because an event that already fired is not replayed. Then open the staging page with the banner unanswered.

    Node.js
    import { chromium } from 'playwright-core';
    
    const browser = await chromium.connectOverCDP(process.env.CDP_URL); // cdp_url from the session response: a secret
    const context = browser.contexts()[0];
    
    // Register the listener before any page script runs: an event that already fired is not replayed.
    await context.addInitScript(() => {
    	window.__noxEvents = [];
    	document.addEventListener('noxtica:collected', (e) =>
    		window.__noxEvents.push({ detail: e.detail, mode: window.noxticaClient?.getConsent().mode }));
    });
    
    const page = await context.newPage();
    const requests = [];
    page.on('request', (r) => requests.push(`${r.method()} ${new URL(r.url()).pathname}`));
    await page.goto(process.env.PAGE_URL, { waitUntil: 'load' });
    await page.waitForFunction(() => window.__noxEvents?.length > 0, null, { timeout: 10_000 });
  4. Assert what the page did

    With the mode api and nothing granted, the documentation expects the core script, one token request, a session token and a collected event that says consent is required. It expects no nox_ key in local storage, no device cookie and no IndexedDB database before the visitor answers. Read cookies from the browser context: the page's own cookie property hides HttpOnly cookies. Count the requests the page makes, remembering that the page's own document is one of them.

    Node.js
    const expected = process.env.EXPECTED_MODE ?? 'api';
    const state = await page.evaluate(async () => ({
    	events: window.__noxEvents,
    	noxKeys: Object.keys(localStorage).filter((k) => k.startsWith('nox_')),
    	sessionKeys: Object.keys(sessionStorage).length,
    	indexedDb: (await indexedDB.databases()).map((db) => db.name),
    }));
    const cookies = await context.cookies(); // includes HttpOnly cookies, which document.cookie hides
    
    const failures = [];
    const check = (ok, msg) => { if (!ok) failures.push(msg); };
    check(requests.filter((r) => /\/noxtica-collector-core(\.[0-9a-f]+)?\.js$/.test(r)).length === 1, 'core script not requested exactly once');
    check(requests.filter((r) => r === 'POST /client/token').length === 1, 'not exactly one token request');
    check(state.events.length === 1 && state.events[0].mode === expected, `consent mode is not ${expected}`);
    check(state.events[0]?.detail?.skipped === 'consent_required', 'collected event is not consent_required');
    check(state.sessionKeys > 0, 'no session token stored');
    check(state.noxKeys.length === 0, 'nox_ keys in localStorage');
    check(cookies.length === 0, 'cookies set before consent');
    check(state.indexedDb.length === 0, 'IndexedDB databases created');
    await browser.close(); // disconnects only; step 5 releases the session
    if (failures.length) { console.error(failures.join('\n')); process.exitCode = 1; }
  5. Release the lease

    End the session through the BrowserX API or command line, with its generation and controller token, so the browser is closed and its profile removed. Closing your Playwright connection only disconnects; the browser stays until you release it.

    Shell
    browserx session release <session-id> --token <controller token>

What a passing run shows

The reported mode equals the one you configured, the collected event carries the consent-required marker, and the page stored nothing in the device stores. A mode that differs means the domain setting changed or the wrong domain's key is on the page.

Limits

  • The script reads page state. It does not test how your banner looks or whether your consent platform calls the Noxtica client at the right time.
  • A clean Chromium is not your visitors' browsers. Run the check in the browsers you support with your own tooling as well.
  • The DevTools address is a bearer token. Anyone who has it can control the browser until the session ends.
  • BrowserX refuses loopback and private destinations by default. A staging host on a private address works only after you list its range in egress.allow_cidrs; a host on a public address needs no setting.

Four checks

All open-source test guides