/* eslint-disable */ module.exports = async (page, scenario, vp, isReference, browserContext) => { console.log('onBefore: Setting up Gatekeeper Auth Cookie...'); // BackstopJS might be hitting localhost, testing, or staging URLs const gatekeeperPassword = process.env.GATEKEEPER_PASSWORD || 'klz2026'; // Extract domain from the scenario URL let targetDomain = 'localhost'; try { const urlObj = new URL(scenario.url); targetDomain = urlObj.hostname; } catch (e) { // ignore } // Inject the ForwardAuth session cookie await page.setCookie({ name: 'klz_gatekeeper_session', value: gatekeeperPassword, domain: targetDomain, // Puppeteer requires exact or matching domain for cookies path: '/', httpOnly: true, secure: targetDomain !== 'localhost' && targetDomain !== 'host.docker.internal', }); };