Files
computer-playbook/roles/test-e2e-playwright/files/onion-test.js
kevinveenbirkenbachandClaude Opus 4.8 5abfcfc6d6 feat(e2e): shared Tor-aware Playwright harness
Promote the Firefox onion fixture (secure-context .onion prefs, SOCKS
remote-DNS) from web-app-dashboard to test-e2e-playwright as the single
source of truth; the dashboard copy now re-exports it. Stage the shared
fixture on all three paths (deploy runner, lint-playwright, rerun-spec).

gotoOnion: onion navigations default to waitUntil=domcontentloaded —
heavy chunked SPAs (Element) serialise 30+ bundle requests over Tor, so
the load event regularly exceeds the navigation cap; callers' explicit
onion-scaled selector waits cover app boot instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-12 10:56:13 +02:00

44 lines
1.6 KiB
JavaScript

/**
* Custom Playwright `test` whose worker-scoped `browser` is launched directly so
* Firefox user-prefs actually apply (the test runner ignores
* `use.launchOptions.firefoxUserPrefs`). On Firefox — the browser the real Tor
* Browser is based on — set the prefs that make `.onion` a secure context
* (RFC 7686) so the Web Crypto API used by keycloak-js is available, and route
* `.onion` through the SOCKS proxy. Chromium/clearnet launches unchanged.
*/
const base = require("@playwright/test");
const isOnion = Object.values(process.env).some(
(value) => typeof value === "string" && /\bhttps?:\/\/[^/,\s"']+\.onion\b/i.test(value)
);
const test = base.test.extend({
browser: async ({ playwright }, use) => {
const proxy = process.env.PLAYWRIGHT_PROXY
? { server: process.env.PLAYWRIGHT_PROXY }
: undefined;
let browser;
if (isOnion) {
browser = await playwright.firefox.launch({
proxy,
firefoxUserPrefs: {
"dom.securecontext.allowlist_onions": true,
"network.proxy.socks_remote_dns": true,
"network.dns.blockDotOnion": false,
"network.http.sendOriginHeader": 2,
"network.http.referer.hideOnionSource": false,
"security.mixed_content.upgrade_display_content": false,
"security.mixed_content.block_display_content": false,
"security.mixed_content.block_active_content": false,
},
});
} else {
browser = await playwright.chromium.launch({ proxy });
}
await use(browser);
await browser.close();
},
});
module.exports = { ...base, test };