@duckduckgo/autoconsent 18.9.0 → 18.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/lib/regional-testing/harness.mjs +73 -6
- package/.agents/skills/oxylabs-testing/SKILL.md +4 -3
- package/.agents/skills/oxylabs-testing/scripts/oxylabs.mjs +26 -3
- package/.agents/skills/oxylabs-testing/scripts/oxylabs.test.mjs +27 -1
- package/.agents/skills/proxy-testing/SKILL.md +7 -2
- package/.agents/skills/proxy-testing/scripts/regional-proxy.mjs +4 -2
- package/.agents/skills/proxy-testing/scripts/regional-proxy.test.mjs +152 -2
- package/CHANGELOG.md +164 -0
- package/Jenkinsfile +22 -27
- package/data/coverage.json +14165 -3824
- package/dist/addon-firefox/background.bundle.js +9 -0
- package/dist/addon-firefox/compact-rules.json +1 -1
- package/dist/addon-firefox/content.bundle.js +14 -2
- package/dist/addon-firefox/manifest.json +1 -1
- package/dist/addon-firefox/rule-index.json +1 -1
- package/dist/addon-firefox/rules.json +1 -1
- package/dist/addon-mv3/background.bundle.js +9 -0
- package/dist/addon-mv3/compact-rules.json +1 -1
- package/dist/addon-mv3/content.bundle.js +14 -2
- package/dist/addon-mv3/manifest.json +1 -1
- package/dist/addon-mv3/rule-index.json +1 -1
- package/dist/addon-mv3/rules.json +1 -1
- package/dist/autoconsent.cjs.js +14 -2
- package/dist/autoconsent.esm.js +14 -2
- package/dist/autoconsent.playwright.js +14 -2
- package/dist/autoconsent.standalone.js +15 -3
- package/dist/heuristics.cjs.js +5 -2
- package/dist/heuristics.mjs +5 -2
- package/dist/types/eval-snippets.d.ts +2 -0
- package/lib/eval-snippets.ts +9 -0
- package/lib/heuristic-literals.ts +2 -1
- package/lib/heuristic-patterns.ts +3 -1
- package/package.json +1 -1
- package/playwright/runner.ts +30 -2
- package/rules/autoconsent/7plus.json +44 -0
- package/rules/autoconsent/adv-gr-jp.json +29 -0
- package/rules/autoconsent/agentii-getsbet-ro.json +19 -0
- package/rules/autoconsent/alza-cookies-info.json +36 -0
- package/rules/autoconsent/amasty-gdpr-hyva.json +73 -50
- package/rules/autoconsent/amazon.json +5 -2
- package/rules/autoconsent/amgueddfa-cms.json +46 -0
- package/rules/autoconsent/anowave-gtm.json +21 -0
- package/rules/autoconsent/anthropic.json +2 -2
- package/rules/autoconsent/apteka911-ua.json +29 -0
- package/rules/autoconsent/artfund.json +18 -0
- package/rules/autoconsent/babylonbee.json +1 -1
- package/rules/autoconsent/betsson-fr.json +45 -0
- package/rules/autoconsent/bladehq.json +13 -0
- package/rules/autoconsent/brandfetch.json +24 -0
- package/rules/autoconsent/bravissimo.json +18 -0
- package/rules/autoconsent/bristan-group.json +58 -0
- package/rules/autoconsent/bswhealth.json +11 -8
- package/rules/autoconsent/captain-compliance.json +30 -0
- package/rules/autoconsent/cardiff-university.json +37 -0
- package/rules/autoconsent/cgov-cookiebanner.json +9 -0
- package/rules/autoconsent/chrono24.json +54 -0
- package/rules/autoconsent/civic-govuk-cookiecontrol.json +16 -0
- package/rules/autoconsent/classbento.json +38 -0
- package/rules/autoconsent/collectingcars.json +18 -0
- package/rules/autoconsent/conscious-solutions.json +25 -0
- package/rules/autoconsent/consentik-notice.json +15 -0
- package/rules/autoconsent/consentik.json +25 -0
- package/rules/autoconsent/cookie-banner-required-only.json +17 -0
- package/rules/autoconsent/cookiebanner-closecookie.json +9 -0
- package/rules/autoconsent/cookieconsent3.json +1 -1
- package/rules/autoconsent/cookiesjsr.json +12 -8
- package/rules/autoconsent/copaair.json +33 -0
- package/rules/autoconsent/crocobet.json +35 -0
- package/rules/autoconsent/crosswater.co.uk.json +41 -0
- package/rules/autoconsent/de-volksbank.json +28 -5
- package/rules/autoconsent/derby-council.json +46 -0
- package/rules/autoconsent/detector-aero.json +21 -0
- package/rules/autoconsent/disturbia.json +38 -0
- package/rules/autoconsent/dobarkod-cookiebanner.json +10 -0
- package/rules/autoconsent/dpgmedia-nl.json +8 -8
- package/rules/autoconsent/energydashboard.co.uk.json +19 -0
- package/rules/autoconsent/ensighten.json +25 -1
- package/rules/autoconsent/eon-nl-cookiewall.json +30 -0
- package/rules/autoconsent/exceed-lms.json +10 -0
- package/rules/autoconsent/expressvpn.json +55 -0
- package/rules/autoconsent/fictionexpress.json +33 -0
- package/rules/autoconsent/food-standards-agency.json +46 -0
- package/rules/autoconsent/freak-no.json +16 -0
- package/rules/autoconsent/fullertonhotels.com.json +37 -6
- package/rules/autoconsent/fundednext.json +16 -0
- package/rules/autoconsent/furniture-com.json +68 -0
- package/rules/autoconsent/globes.json +40 -0
- package/rules/autoconsent/gm-consent.json +20 -0
- package/rules/autoconsent/gotrust.json +95 -0
- package/rules/autoconsent/grocefully.json +25 -0
- package/rules/autoconsent/hds-cookie-consent.json +10 -0
- package/rules/autoconsent/headfirstbristol.json +12 -0
- package/rules/autoconsent/healthysupplies.json +18 -0
- package/rules/autoconsent/helvy.co.uk.json +21 -0
- package/rules/autoconsent/holland-watch-group.json +12 -0
- package/rules/autoconsent/hubspot-cosmetic.json +15 -0
- package/rules/autoconsent/hubspot.json +4 -1
- package/rules/autoconsent/hyperoptic.json +44 -0
- package/rules/autoconsent/hypovereinsbank.json +39 -0
- package/rules/autoconsent/incogni.json +23 -0
- package/rules/autoconsent/islamqa.org.json +31 -0
- package/rules/autoconsent/itemsatis.json +41 -0
- package/rules/autoconsent/ixo-cookie-prompt.json +12 -0
- package/rules/autoconsent/kela-fi.json +32 -0
- package/rules/autoconsent/kenstechtips.json +12 -0
- package/rules/autoconsent/keurig.com.json +47 -0
- package/rules/autoconsent/krillion.json +13 -0
- package/rules/autoconsent/lawhive.json +27 -0
- package/rules/autoconsent/laxd.json +29 -0
- package/rules/autoconsent/lessonup.json +24 -0
- package/rules/autoconsent/ligonier.json +13 -0
- package/rules/autoconsent/madeiramadeira.json +31 -0
- package/rules/autoconsent/manage-cookie-modal.json +52 -0
- package/rules/autoconsent/marriott-notice.json +28 -0
- package/rules/autoconsent/mccoysguide.json +40 -0
- package/rules/autoconsent/mercadolibre.json +3 -3
- package/rules/autoconsent/myfooddiary.json +36 -0
- package/rules/autoconsent/nationwidevehiclecontracts.json +37 -0
- package/rules/autoconsent/natural-intelligence.json +21 -0
- package/rules/autoconsent/naturalnews.json +32 -0
- package/rules/autoconsent/nfl.json +32 -0
- package/rules/autoconsent/noon.json +41 -0
- package/rules/autoconsent/odia.json +12 -0
- package/rules/autoconsent/op-consent-manager.json +17 -0
- package/rules/autoconsent/opencart-google-consent-v2.json +27 -0
- package/rules/autoconsent/pandectes.json +13 -4
- package/rules/autoconsent/paperlesspost.json +64 -0
- package/rules/autoconsent/passenger-cookie-opt-in.json +15 -0
- package/rules/autoconsent/peda-net.json +34 -0
- package/rules/autoconsent/peterchristian.json +35 -0
- package/rules/autoconsent/pieeye.json +25 -0
- package/rules/autoconsent/playdoit-mx.json +32 -0
- package/rules/autoconsent/pmc-privacy-banner.json +40 -6
- package/rules/autoconsent/prestigeflowers.json +21 -0
- package/rules/autoconsent/profootballmania.json +21 -0
- package/rules/autoconsent/pvh.json +29 -0
- package/rules/autoconsent/quorn.json +17 -0
- package/rules/autoconsent/randewoo.ru.json +37 -0
- package/rules/autoconsent/rct-cookies-modal.json +36 -0
- package/rules/autoconsent/realfoods-co-uk.json +18 -0
- package/rules/autoconsent/roguefitness.json +18 -0
- package/rules/autoconsent/rosbalt-ru.json +35 -0
- package/rules/autoconsent/securiti-hybrid.json +30 -0
- package/rules/autoconsent/shopblocks.json +41 -0
- package/rules/autoconsent/sicredi-frame.json +16 -0
- package/rules/autoconsent/sicredi.json +0 -1
- package/rules/autoconsent/simplepractice.com.json +60 -0
- package/rules/autoconsent/skroutz.json +33 -0
- package/rules/autoconsent/spares2repair.json +42 -0
- package/rules/autoconsent/spusu.json +18 -0
- package/rules/autoconsent/sykescottages.json +49 -0
- package/rules/autoconsent/termsfeed.json +4 -4
- package/rules/autoconsent/truecar.json +5 -5
- package/rules/autoconsent/trustarc-newcm.json +37 -6
- package/rules/autoconsent/ubuy.json +10 -0
- package/rules/autoconsent/ukplanettools.json +45 -0
- package/rules/autoconsent/vidal-ru.json +12 -0
- package/rules/autoconsent/virginwines-co-uk.json +32 -0
- package/rules/autoconsent/visualsoft.json +24 -0
- package/rules/autoconsent/vsco.json +27 -0
- package/rules/autoconsent/vystarcu.json +17 -0
- package/rules/autoconsent/web-labs-cookie-consent.json +69 -0
- package/rules/autoconsent/webnetism.json +42 -0
- package/rules/autoconsent/whatnot.json +32 -0
- package/rules/autoconsent/wow-forever.json +33 -0
- package/rules/autoconsent/wso2-identity-server.json +30 -0
- package/rules/autoconsent/xhamster-eu.json +1 -1
- package/rules/autoconsent/xhamster-us.json +1 -1
- package/rules/autoconsent/yourparkingspace.json +47 -0
- package/rules/compact-rules.json +1 -1
- package/rules/rule-index.json +1 -1
- package/rules/rules.json +1 -1
- package/tests/7plus.spec.ts +6 -0
- package/tests/adv-gr-jp.spec.ts +3 -0
- package/tests/agentii-getsbet-ro.spec.ts +3 -0
- package/tests/alza-cookies-info.spec.ts +10 -0
- package/tests/amasty-gdpr-hyva.spec.ts +9 -0
- package/tests/amazon.spec.ts +7 -14
- package/tests/amgueddfa-cms.spec.ts +3 -0
- package/tests/anowave-gtm.spec.ts +8 -0
- package/tests/anthropic.spec.ts +6 -1
- package/tests/apteka911-ua.spec.ts +3 -0
- package/tests/artfund.spec.ts +3 -0
- package/tests/babylonbee.spec.ts +1 -1
- package/tests/betsson-fr.spec.ts +12 -0
- package/tests/bladehq.spec.ts +3 -0
- package/tests/brandfetch.spec.ts +5 -0
- package/tests/bravissimo.spec.ts +9 -0
- package/tests/bristan-group.spec.ts +3 -0
- package/tests/bswhealth.spec.ts +1 -1
- package/tests/captain-compliance.spec.ts +15 -0
- package/tests/cardiff-university.spec.ts +3 -0
- package/tests/cgov-cookiebanner.spec.ts +6 -0
- package/tests/chrono24.spec.ts +3 -0
- package/tests/civic-govuk-cookiecontrol.spec.ts +9 -0
- package/tests/classbento.spec.ts +3 -0
- package/tests/collectingcars.spec.ts +3 -0
- package/tests/conscious-solutions.spec.ts +10 -0
- package/tests/consentik-notice.spec.ts +3 -0
- package/tests/consentik.spec.ts +8 -0
- package/tests/cookie-banner-required-only.spec.ts +9 -0
- package/tests/cookiebanner-closecookie.spec.ts +3 -0
- package/tests/cookieconsent3.spec.ts +4 -5
- package/tests/cookiesjsr.spec.ts +3 -0
- package/tests/copaair.spec.ts +3 -0
- package/tests/crocobet.spec.ts +11 -0
- package/tests/crosswater.co.uk.spec.ts +3 -0
- package/tests/de-volksbank.spec.ts +14 -3
- package/tests/derby-council.spec.ts +8 -0
- package/tests/detector-aero.spec.ts +3 -0
- package/tests/disturbia.spec.ts +6 -0
- package/tests/dobarkod-cookiebanner.spec.ts +8 -0
- package/tests/energydashboard.co.uk.spec.ts +3 -0
- package/tests/ensighten.spec.ts +9 -0
- package/tests/eon-nl-cookiewall.spec.ts +6 -0
- package/tests/exceed-lms.spec.ts +8 -0
- package/tests/expressvpn.spec.ts +3 -0
- package/tests/fictionexpress.spec.ts +3 -0
- package/tests/food-standards-agency.spec.ts +3 -0
- package/tests/freak-no.spec.ts +4 -0
- package/tests/fullertonhotels.com.spec.ts +17 -2
- package/tests/fundednext.spec.ts +6 -0
- package/tests/furniture-com.spec.ts +6 -0
- package/tests/globes.spec.ts +3 -0
- package/tests/gm-consent.spec.ts +9 -0
- package/tests/gotrust.spec.ts +9 -0
- package/tests/grocefully.spec.ts +5 -0
- package/tests/hds-cookie-consent.spec.ts +8 -0
- package/tests/headfirstbristol.spec.ts +3 -0
- package/tests/healthysupplies.spec.ts +3 -0
- package/tests/helvy.co.uk.spec.ts +3 -0
- package/tests/holland-watch-group.spec.ts +8 -0
- package/tests/hubspot-cosmetic.spec.ts +6 -0
- package/tests/hyperoptic.spec.ts +3 -0
- package/tests/hypovereinsbank.spec.ts +4 -0
- package/tests/incogni.spec.ts +3 -0
- package/tests/islamqa.org.spec.ts +3 -0
- package/tests/itemsatis.spec.ts +3 -0
- package/tests/ixo-cookie-prompt.spec.ts +8 -0
- package/tests/kela-fi.spec.ts +3 -0
- package/tests/kenstechtips.spec.ts +3 -0
- package/tests/keurig.com.spec.ts +3 -0
- package/tests/krillion.spec.ts +6 -0
- package/tests/lawhive.spec.ts +3 -0
- package/tests/laxd.spec.ts +6 -0
- package/tests/lessonup.spec.ts +3 -0
- package/tests/ligonier.spec.ts +3 -0
- package/tests/madeiramadeira.spec.ts +3 -0
- package/tests/manage-cookie-modal.spec.ts +3 -0
- package/tests/marriott-notice.spec.ts +8 -0
- package/tests/mccoysguide.spec.ts +3 -0
- package/tests/myfooddiary.spec.ts +3 -0
- package/tests/nationwidevehiclecontracts.spec.ts +3 -0
- package/tests/natural-intelligence.spec.ts +9 -0
- package/tests/naturalnews.spec.ts +3 -0
- package/tests/nfl.spec.ts +3 -0
- package/tests/noon.spec.ts +5 -0
- package/tests/odia.spec.ts +3 -0
- package/tests/op-consent-manager.spec.ts +3 -0
- package/tests/opencart-google-consent-v2.spec.ts +8 -0
- package/tests/pandectes.spec.ts +3 -0
- package/tests/paperlesspost.spec.ts +5 -0
- package/tests/passenger-cookie-opt-in.spec.ts +14 -0
- package/tests/peda-net.spec.ts +3 -0
- package/tests/peterchristian.spec.ts +3 -0
- package/tests/pieeye.spec.ts +16 -0
- package/tests/playdoit-mx.spec.ts +3 -0
- package/tests/pmc-privacy-banner.spec.ts +3 -0
- package/tests/prestigeflowers.spec.ts +5 -0
- package/tests/profootballmania.spec.ts +3 -0
- package/tests/pvh.spec.ts +8 -0
- package/tests/quorn.spec.ts +3 -0
- package/tests/randewoo.ru.spec.ts +3 -0
- package/tests/rct-cookies-modal.spec.ts +13 -0
- package/tests/realfoods-co-uk.spec.ts +3 -0
- package/tests/roguefitness.spec.ts +3 -0
- package/tests/rosbalt-ru.spec.ts +3 -0
- package/tests/securiti-hybrid.spec.ts +13 -0
- package/tests/shopblocks.spec.ts +8 -0
- package/tests/sicredi-frame.spec.ts +11 -0
- package/tests/sicredi.spec.ts +1 -1
- package/tests/simplepractice.com.spec.ts +4 -0
- package/tests/skroutz.spec.ts +6 -0
- package/tests/spares2repair.spec.ts +5 -0
- package/tests/spusu.spec.ts +3 -0
- package/tests/sykescottages.spec.ts +3 -0
- package/tests/termsfeed.spec.ts +6 -2
- package/tests/truecar.spec.ts +1 -1
- package/tests/trustarc-newcm.spec.ts +16 -0
- package/tests/ubuy.spec.ts +5 -0
- package/tests/ukplanettools.spec.ts +3 -0
- package/tests/vidal-ru.spec.ts +3 -0
- package/tests/virginwines-co-uk.spec.ts +3 -0
- package/tests/visualsoft.spec.ts +3 -0
- package/tests/vsco.spec.ts +7 -0
- package/tests/vystarcu.spec.ts +3 -0
- package/tests/web-labs-cookie-consent.spec.ts +12 -0
- package/tests/webnetism.spec.ts +10 -0
- package/tests/whatnot.spec.ts +3 -0
- package/tests/wow-forever.spec.ts +3 -0
- package/tests/wso2-identity-server.spec.ts +3 -0
- package/tests/xhamster-eu.spec.ts +2 -0
- package/tests/xhamster-us.spec.ts +2 -0
- package/tests/yourparkingspace.spec.ts +3 -0
- package/tests-wtr/heuristics/heuristics-utils.test.ts +3 -0
- package/rules/generated/auto_AU_u-buy.com.au_rg0.json +0 -37
- package/rules/generated/auto_CH_seetickets.com_4b2.json +0 -40
- package/rules/generated/auto_GB_charlesclinkard.co.uk_0.json +0 -37
- package/tests/generated/auto_AU_u-buy.com.au_rg0.spec.ts +0 -2
- package/tests/generated/auto_CH_seetickets.com_4b2.spec.ts +0 -6
- package/tests/generated/auto_GB_charlesclinkard.co.uk_0.spec.ts +0 -6
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
/** @typedef {import('../../../lib/types.js').Config} Config */
|
|
14
|
+
/** @typedef {import('../../../lib/types.js').HeuristicLevel} HeuristicLevel */
|
|
15
|
+
/** @typedef {import('../../../lib/types.js').RuleBundle} RuleBundle */
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* @typedef {import('../../../playwright/isolated-world.mjs').MessageTransport} MessageTransport
|
|
@@ -28,6 +30,10 @@
|
|
|
28
30
|
* @property {number} [navigationTimeout=45000]
|
|
29
31
|
* @property {number} [completionTimeout=45000]
|
|
30
32
|
* @property {number} [detectionTimeout] - How long to wait for `cmpDetected` before giving up. Defaults to `completionTimeout`.
|
|
33
|
+
* @property {string[]} [disabledCmps=[]] - Rule names autoconsent skips, e.g. to see what handles the page without a rule.
|
|
34
|
+
* @property {HeuristicLevel} [heuristicMode='tier2'] - Heuristic level; 'tier1' leaves out popups whose only button is Accept.
|
|
35
|
+
* @property {string} [emulateDevice] - Playwright device to emulate on Chromium, e.g. 'Pixel 7'. Desktop when unset. Applied by the providers' `testUrl` when they open the page.
|
|
36
|
+
* @property {boolean} [gpc=true] - Send the Global Privacy Control signal, as DuckDuckGo browsers do. `false` tests a page the way a spec without the `gpc` option does.
|
|
31
37
|
*/
|
|
32
38
|
|
|
33
39
|
/**
|
|
@@ -76,8 +82,10 @@
|
|
|
76
82
|
*/
|
|
77
83
|
|
|
78
84
|
import fs from 'fs';
|
|
85
|
+
import { createRequire } from 'module';
|
|
79
86
|
import path from 'path';
|
|
80
87
|
import { fileURLToPath } from 'url';
|
|
88
|
+
import { devices } from 'playwright';
|
|
81
89
|
import { injectIntoIsolatedWorld } from '../../../playwright/isolated-world.mjs';
|
|
82
90
|
|
|
83
91
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -86,6 +94,9 @@ export const projectRoot = path.resolve(__dirname, '../../..');
|
|
|
86
94
|
const contentScript = fs.readFileSync(path.join(projectRoot, 'dist/autoconsent.playwright.js'), 'utf8');
|
|
87
95
|
const rulesJson = JSON.parse(fs.readFileSync(path.join(projectRoot, 'rules/rules.json'), 'utf-8'));
|
|
88
96
|
const fullRules = rulesJson.autoconsent;
|
|
97
|
+
const compactRules = JSON.parse(fs.readFileSync(path.join(projectRoot, 'rules/compact-rules.json'), 'utf-8'));
|
|
98
|
+
// The built package entry, since this plain-JS harness can't import the TypeScript sources.
|
|
99
|
+
const { filterCompactRules } = createRequire(import.meta.url)('../../../dist/autoconsent.cjs.js');
|
|
89
100
|
|
|
90
101
|
/** All regions in the verification policy (every region with a regional proxy). */
|
|
91
102
|
export const ALL_REGIONS = ['us', 'gb', 'au', 'ca', 'de', 'fr', 'nl', 'ch', 'no', 'it', 'es', 'pl', 'se', 'dk', 'jp'];
|
|
@@ -96,6 +107,52 @@ export const CORE_REGIONS = ['us', 'gb', 'de'];
|
|
|
96
107
|
/** Expanded pass: escalation set covering all non-GDPR regimes plus GDPR representatives. */
|
|
97
108
|
export const EXPANDED_REGIONS = ['us', 'gb', 'de', 'fr', 'nl', 'pl', 'au', 'ca', 'jp'];
|
|
98
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Browser context options that emulate a Playwright device on Chromium: viewport, user agent, touch.
|
|
112
|
+
* @param {string} [deviceName] - A key of Playwright's `devices`, e.g. 'Pixel 7'.
|
|
113
|
+
* @returns {import('playwright').BrowserContextOptions}
|
|
114
|
+
*/
|
|
115
|
+
export function deviceContextOptions(deviceName) {
|
|
116
|
+
if (!deviceName) {
|
|
117
|
+
return {};
|
|
118
|
+
}
|
|
119
|
+
const descriptor = devices[deviceName];
|
|
120
|
+
if (!descriptor) {
|
|
121
|
+
throw new Error(`Unknown Playwright device "${deviceName}".`);
|
|
122
|
+
}
|
|
123
|
+
// The browser is always Chromium here, whatever the device ships with.
|
|
124
|
+
const { defaultBrowserType: _browserType, ...contextOptions } = descriptor;
|
|
125
|
+
return contextOptions;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Send the Global Privacy Control signal from a page, the way the spec runner does: the
|
|
130
|
+
* `Sec-GPC: 1` request header and `navigator.globalPrivacyControl`. Call before navigating.
|
|
131
|
+
* @param {Page} page
|
|
132
|
+
*/
|
|
133
|
+
export async function enableGpc(page) {
|
|
134
|
+
await page.setExtraHTTPHeaders({ 'Sec-GPC': '1' });
|
|
135
|
+
await page.addInitScript(() => {
|
|
136
|
+
Object.defineProperty(Navigator.prototype, 'globalPrivacyControl', { get: () => true, configurable: true });
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The rules a frame gets in reply to its `init`. Like the browser extension, a frame gets only the compact
|
|
142
|
+
* rules that can run in it, so ad-heavy pages don't parse the whole bundle in every iframe. Opt-in gets the
|
|
143
|
+
* full rules, since compact rules have no opt-in steps.
|
|
144
|
+
* @param {'optOut'|'optIn'|null} action
|
|
145
|
+
* @param {string} url - The frame's URL.
|
|
146
|
+
* @param {boolean} mainFrame
|
|
147
|
+
* @returns {RuleBundle}
|
|
148
|
+
*/
|
|
149
|
+
export function rulesForFrame(action, url, mainFrame) {
|
|
150
|
+
if (action === 'optIn') {
|
|
151
|
+
return { autoconsent: fullRules };
|
|
152
|
+
}
|
|
153
|
+
return { autoconsent: [], compact: filterCompactRules(compactRules, { url, mainFrame }) };
|
|
154
|
+
}
|
|
155
|
+
|
|
99
156
|
/**
|
|
100
157
|
* Inject autoconsent into a page. Call before navigating to the target URL.
|
|
101
158
|
*
|
|
@@ -115,13 +172,13 @@ export async function injectAutoconsent(page, options, provider, extension = {})
|
|
|
115
172
|
const config = {
|
|
116
173
|
enabled: true,
|
|
117
174
|
autoAction: action,
|
|
118
|
-
disabledCmps: [],
|
|
175
|
+
disabledCmps: options.disabledCmps ?? [],
|
|
119
176
|
enablePrehide: true,
|
|
120
177
|
detectRetries: 20,
|
|
121
178
|
enableCosmeticRules: true,
|
|
122
179
|
enableGeneratedRules: true,
|
|
123
180
|
enableHeuristicDetection: true,
|
|
124
|
-
heuristicMode: 'tier2',
|
|
181
|
+
heuristicMode: options.heuristicMode ?? 'tier2',
|
|
125
182
|
// The engine runs in the isolated world; eval snippets are forwarded to the main world.
|
|
126
183
|
isMainWorld: false,
|
|
127
184
|
logs: { lifecycle: true, rulesteps: true, detectionsteps: false, evals: false, errors: true, messages: false, waits: false },
|
|
@@ -139,13 +196,17 @@ export async function injectAutoconsent(page, options, provider, extension = {})
|
|
|
139
196
|
// This split mirrors the browser extension: the engine lives in an isolated world,
|
|
140
197
|
// while `eval` snippets execute in the page's main world.
|
|
141
198
|
/** @type {MessageHandlerFactory} */
|
|
142
|
-
const createMessageHandler = ({ sendToContentScript, evalInMainWorld }) => {
|
|
199
|
+
const createMessageHandler = ({ sendToContentScript, evalInMainWorld, isMainFrame }) => {
|
|
143
200
|
return async function handleMessage(msg, frameRef) {
|
|
144
201
|
received.push(msg);
|
|
145
202
|
extension.onMessage?.(msg);
|
|
146
203
|
switch (msg.type) {
|
|
147
204
|
case 'init':
|
|
148
|
-
await sendToContentScript(frameRef, {
|
|
205
|
+
await sendToContentScript(frameRef, {
|
|
206
|
+
type: 'initResp',
|
|
207
|
+
config,
|
|
208
|
+
rules: rulesForFrame(action, msg.url ?? '', isMainFrame(frameRef)),
|
|
209
|
+
});
|
|
149
210
|
break;
|
|
150
211
|
case 'eval': {
|
|
151
212
|
let result = false;
|
|
@@ -297,6 +358,9 @@ export async function runTest(page, url, regionKey, options, provider) {
|
|
|
297
358
|
|
|
298
359
|
try {
|
|
299
360
|
const ctx = await provider.inject(page, options);
|
|
361
|
+
if (options.gpc !== false) {
|
|
362
|
+
await enableGpc(page);
|
|
363
|
+
}
|
|
300
364
|
await page.goto(url, { waitUntil: 'commit', timeout: navTimeout });
|
|
301
365
|
await provider.afterNavigation?.(page, ctx, options);
|
|
302
366
|
|
|
@@ -325,9 +389,12 @@ export async function runTest(page, url, regionKey, options, provider) {
|
|
|
325
389
|
const tag = provider.screenshotTag ? `-${provider.screenshotTag}` : '';
|
|
326
390
|
const filepath = path.join(screenshotsDir, `${domain}-${regionKey}${tag}-final.jpg`);
|
|
327
391
|
fs.mkdirSync(screenshotsDir, { recursive: true });
|
|
328
|
-
|
|
392
|
+
// A remote browser on a busy page can take many seconds before Playwright captures.
|
|
393
|
+
await page.screenshot({ path: filepath, quality: 50, scale: 'css', timeout: 30000, type: 'jpeg' });
|
|
329
394
|
result.screenshotPaths.push(filepath);
|
|
330
|
-
} catch {
|
|
395
|
+
} catch (e) {
|
|
396
|
+
result.errors.push(`Screenshot failed: ${String(e instanceof Error ? e.message : e).split('\n')[0]}`);
|
|
397
|
+
}
|
|
331
398
|
|
|
332
399
|
return result;
|
|
333
400
|
} catch (e) {
|
|
@@ -18,7 +18,7 @@ The region policy (core and expanded sets) is the one in the `proxy-testing` ski
|
|
|
18
18
|
## Prerequisites
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
npm run prepublish # builds dist/
|
|
21
|
+
npm run prepublish # builds dist/ (content script and package bundles) and rules/rules.json, rules/compact-rules.json
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
Environment variables:
|
|
@@ -64,11 +64,12 @@ const result = await withOxylabsPage('de', { device: 'mobile' }, async (page) =>
|
|
|
64
64
|
- `isOxylabsConfigured()` — whether `OXYLABS_USER` and `OXYLABS_PASSWORD` are set.
|
|
65
65
|
- `formatResult(result)`, `CORE_REGIONS`, `EXPANDED_REGIONS`, `ALL_REGIONS` — same as `proxy-testing`.
|
|
66
66
|
|
|
67
|
-
Options: everything `testPage` takes in `proxy-testing` (`action`, `screenshotsDir`, `navigationTimeout`, `completionTimeout`, `detectionTimeout`), plus:
|
|
67
|
+
Options: everything `testPage` takes in `proxy-testing` (`action`, `screenshotsDir`, `navigationTimeout`, `completionTimeout`, `detectionTimeout`, `disabledCmps`, `heuristicMode`, `gpc`), plus:
|
|
68
68
|
|
|
69
69
|
| Option | Default | Description |
|
|
70
70
|
|--------|---------|-------------|
|
|
71
|
-
| `device` | `'desktop'` | `'desktop' \| 'mobile'` — sets [`?p_device=`](https://developers.oxylabs.io/products/agent-browser/device-type)
|
|
71
|
+
| `device` | `'desktop'` | `'desktop' \| 'mobile'` — sets [`?p_device=`](https://developers.oxylabs.io/products/agent-browser/device-type), which gives an Android user agent but no touch and a desktop-sized page. With `'mobile'`, `testUrl` and `withOxylabsPage` open the page in a context with touch and a phone viewport (`OXYLABS_MOBILE_CONTEXT`), keeping Oxylabs' user agent. Pages stay at least 500px wide, and `navigator.userAgentData` still reports desktop Linux. |
|
|
72
|
+
| `emulateDevice` | none | A Playwright device to emulate instead, e.g. `'Pixel 7'`: its viewport, touch and user agent, which replaces the Oxylabs one. |
|
|
72
73
|
| `solveCaptcha` | `true` | Sends [`?solve_captcha=true`](https://developers.oxylabs.io/products/agent-browser/captcha-handling) so Oxylabs solves captchas on the page, and waits for the solver (see Gotchas). Our account has captcha solving enabled; an account without it gets HTTP 400 for every session. |
|
|
73
74
|
|
|
74
75
|
Screenshots default to `test-results/oxylabs`, named `<domain>-<region>-oxylabs-final.jpg`.
|
|
@@ -36,13 +36,14 @@ import path from 'path';
|
|
|
36
36
|
import { connectOxylabs, createCaptchaTracker, redactCredentials } from '../../../../playwright/oxylabs.mjs';
|
|
37
37
|
import {
|
|
38
38
|
CORE_REGIONS,
|
|
39
|
+
deviceContextOptions,
|
|
39
40
|
emptyResult,
|
|
40
41
|
injectAutoconsent as injectThrough,
|
|
41
42
|
projectRoot,
|
|
42
43
|
runTest,
|
|
43
44
|
} from '../../../lib/regional-testing/harness.mjs';
|
|
44
45
|
|
|
45
|
-
export { ALL_REGIONS, CORE_REGIONS, EXPANDED_REGIONS, formatResult } from '../../../lib/regional-testing/harness.mjs';
|
|
46
|
+
export { ALL_REGIONS, CORE_REGIONS, EXPANDED_REGIONS, deviceContextOptions, formatResult } from '../../../lib/regional-testing/harness.mjs';
|
|
46
47
|
export {
|
|
47
48
|
OXYLABS_LOCAL_REGIONS,
|
|
48
49
|
buildOxylabsEndpoint,
|
|
@@ -101,19 +102,41 @@ export async function testPage(page, url, regionKey, options = {}) {
|
|
|
101
102
|
return redactResult(await runTest(page, url, regionKey, options, provider));
|
|
102
103
|
}
|
|
103
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Touch and a phone-sized viewport for `device: 'mobile'`. Oxylabs' mobile profile sets only the
|
|
107
|
+
* user agent, and a new page would get Playwright's 1280px desktop viewport. The user agent is left
|
|
108
|
+
* to Oxylabs so it matches the rest of its profile. The remote window keeps pages at least 500px wide.
|
|
109
|
+
* @type {import('playwright').BrowserContextOptions}
|
|
110
|
+
*/
|
|
111
|
+
export const OXYLABS_MOBILE_CONTEXT = { viewport: { width: 360, height: 740 }, isMobile: true, hasTouch: true };
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Context options for a page of an Oxylabs session, or null for Playwright's defaults.
|
|
115
|
+
* @param {OxylabsBrowserOptions & { emulateDevice?: string }} options
|
|
116
|
+
* @returns {import('playwright').BrowserContextOptions | null}
|
|
117
|
+
*/
|
|
118
|
+
export function oxylabsContextOptions(options) {
|
|
119
|
+
if (options.emulateDevice) {
|
|
120
|
+
return deviceContextOptions(options.emulateDevice);
|
|
121
|
+
}
|
|
122
|
+
return options.device === 'mobile' ? OXYLABS_MOBILE_CONTEXT : null;
|
|
123
|
+
}
|
|
124
|
+
|
|
104
125
|
/**
|
|
105
126
|
* Run `fn` on a page of a fresh Oxylabs session for a region, then close the session. Throws if
|
|
106
127
|
* the session cannot be opened.
|
|
107
128
|
* @template T
|
|
108
129
|
* @param {string} regionKey
|
|
109
|
-
* @param {OxylabsBrowserOptions} options
|
|
130
|
+
* @param {OxylabsBrowserOptions & { emulateDevice?: string }} options
|
|
110
131
|
* @param {(page: Page) => Promise<T>} fn
|
|
111
132
|
* @returns {Promise<T>}
|
|
112
133
|
*/
|
|
113
134
|
export async function withOxylabsPage(regionKey, options, fn) {
|
|
114
135
|
const browser = await connectOxylabs(regionKey, { device: options.device, solveCaptcha: options.solveCaptcha });
|
|
115
136
|
try {
|
|
116
|
-
|
|
137
|
+
const contextOptions = oxylabsContextOptions(options);
|
|
138
|
+
const context = contextOptions ? await browser.newContext(contextOptions) : null;
|
|
139
|
+
return await fn(await (context ?? browser).newPage());
|
|
117
140
|
} finally {
|
|
118
141
|
try {
|
|
119
142
|
await browser.close();
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
2
|
import { describe, it } from 'node:test';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
OXYLABS_MOBILE_CONTEXT,
|
|
6
|
+
buildOxylabsEndpoint,
|
|
7
|
+
isOxylabsConfigured,
|
|
8
|
+
oxylabsContextOptions,
|
|
9
|
+
oxylabsRegionParams,
|
|
10
|
+
redactCredentials,
|
|
11
|
+
} from './oxylabs.mjs';
|
|
5
12
|
|
|
6
13
|
const env = { OXYLABS_USER: 'user', OXYLABS_PASSWORD: 'p+ss' };
|
|
7
14
|
|
|
@@ -38,3 +45,22 @@ describe('oxylabs config', () => {
|
|
|
38
45
|
);
|
|
39
46
|
});
|
|
40
47
|
});
|
|
48
|
+
|
|
49
|
+
describe('oxylabs pages', () => {
|
|
50
|
+
it('opens desktop pages with Playwright defaults', () => {
|
|
51
|
+
assert.equal(oxylabsContextOptions({}), null);
|
|
52
|
+
assert.equal(oxylabsContextOptions({ device: 'desktop' }), null);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('adds touch to the mobile profile without replacing its user agent', () => {
|
|
56
|
+
const options = oxylabsContextOptions({ device: 'mobile' });
|
|
57
|
+
assert.equal(options, OXYLABS_MOBILE_CONTEXT);
|
|
58
|
+
assert.equal(options?.hasTouch, true);
|
|
59
|
+
assert.equal(options?.isMobile, true);
|
|
60
|
+
assert.equal(options?.userAgent, undefined);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('lets a Playwright device override the mobile profile', () => {
|
|
64
|
+
assert.match(oxylabsContextOptions({ device: 'mobile', emulateDevice: 'iPhone SE' })?.userAgent ?? '', /iPhone/);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -25,7 +25,7 @@ Important! Autoconsent results can have false positives. When testing, always in
|
|
|
25
25
|
## Prerequisites
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
npm run prepublish # builds dist/
|
|
28
|
+
npm run prepublish # builds dist/ (content script and package bundles) and rules/rules.json, rules/compact-rules.json
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
Environment variables:
|
|
@@ -97,10 +97,14 @@ export default defineConfig({
|
|
|
97
97
|
Options (all optional):
|
|
98
98
|
|
|
99
99
|
- `action` — `'optOut'` (default), `'optIn'`, or `null` to only detect (no opt-out/opt-in performed).
|
|
100
|
-
- `screenshotsDir` — directory for the final screenshots (default: `test-results/regional-proxy`).
|
|
100
|
+
- `screenshotsDir` — directory for the final screenshots (default: `test-results/regional-proxy`). If the final screenshot fails, `screenshotPaths` stays empty and `errors` gets `Screenshot failed: <reason>`.
|
|
101
101
|
- `navigationTimeout` — `page.goto` timeout in ms (default `45000`).
|
|
102
102
|
- `completionTimeout` — max wait for autoconsent to finish opt-out/opt-in in ms (default `45000`).
|
|
103
103
|
- `detectionTimeout` — max wait for `cmpDetected` before giving up (default: `completionTimeout`).
|
|
104
|
+
- `disabledCmps` — rule names autoconsent skips (default `[]`), e.g. to see whether another rule or the heuristic handles the page without a rule.
|
|
105
|
+
- `heuristicMode` — heuristic level: `'off'`, `'reject'`, `'tier1'` or `'tier2'` (default `'tier2'`). `'tier1'` leaves out popups whose only button is Accept.
|
|
106
|
+
- `gpc` — send the Global Privacy Control signal (`Sec-GPC: 1` and `navigator.globalPrivacyControl`), as DuckDuckGo browsers do (default `true`). Set `false` to test the way a spec without the `gpc` option does, which is how CI runs most specs.
|
|
107
|
+
- `emulateDevice` — Playwright device to emulate on Chromium, e.g. `'Pixel 7'` (viewport, user agent, touch), applied by `testUrl`. Desktop when unset. Prefer an Android device: an emulated iPhone still exposes Chrome-only APIs such as `navigator.userAgentData`, so a site can tell it is not Safari.
|
|
104
108
|
- `headless` — run Chromium headless (default `true`).
|
|
105
109
|
- `launchOptions` — extra options merged into `chromium.launch()` (e.g. `args`); the regional `proxy` is always applied on top.
|
|
106
110
|
|
|
@@ -131,6 +135,7 @@ await browser.close();
|
|
|
131
135
|
- Never embed proxy credentials in URLs, command lines, logs, traces, or source.
|
|
132
136
|
- Call `injectAutoconsent(page)` before `page.goto()` so the init script is installed before page scripts run.
|
|
133
137
|
- The content script runs in an isolated world (via CDP) and `eval` snippets run in the page's main world, matching the extension. Chromium only.
|
|
138
|
+
- Like the extension, each frame gets only the rules that can run in it: the compact rules filtered by the frame's URL and whether it is the main frame. Opt-in gets the full `rules.json` instead, since compact rules have no opt-in steps.
|
|
134
139
|
- Use a fresh browser per region to avoid leaking proxy state, cookies, cache, or DNS.
|
|
135
140
|
- Some sites localize by more than IP; only add locale/geolocation settings intentionally.
|
|
136
141
|
- Some sites block proxy traffic outright (captcha, 403, endless challenge page). Retest the affected regions with the `oxylabs-testing` skill, and say in the report which regions were tested through Oxylabs. If Oxylabs is blocked too or not available, retest over a direct connection and state explicitly in the report that the result is unproxied. If direct access is blocked too, ask the triager for the popup's HTML pasted from their own browser as a last resort, and note that the rule was written from pasted markup rather than a live run.
|
|
@@ -34,13 +34,14 @@ import path from 'path';
|
|
|
34
34
|
import { chromium } from 'playwright';
|
|
35
35
|
import {
|
|
36
36
|
CORE_REGIONS,
|
|
37
|
+
deviceContextOptions,
|
|
37
38
|
emptyResult,
|
|
38
39
|
injectAutoconsent as injectThrough,
|
|
39
40
|
projectRoot,
|
|
40
41
|
runTest,
|
|
41
42
|
} from '../../../lib/regional-testing/harness.mjs';
|
|
42
43
|
|
|
43
|
-
export { ALL_REGIONS, CORE_REGIONS, EXPANDED_REGIONS, formatResult } from '../../../lib/regional-testing/harness.mjs';
|
|
44
|
+
export { ALL_REGIONS, CORE_REGIONS, EXPANDED_REGIONS, deviceContextOptions, formatResult } from '../../../lib/regional-testing/harness.mjs';
|
|
44
45
|
|
|
45
46
|
/**
|
|
46
47
|
* Build the Playwright proxy object for a region.
|
|
@@ -133,7 +134,8 @@ export async function testUrl(url, regionKey, options = {}) {
|
|
|
133
134
|
let browser = null;
|
|
134
135
|
try {
|
|
135
136
|
browser = await launchRegionalProxyBrowser(regionKey, options);
|
|
136
|
-
const
|
|
137
|
+
const context = await browser.newContext(deviceContextOptions(options.emulateDevice));
|
|
138
|
+
const page = await context.newPage();
|
|
137
139
|
return await testPage(page, url, regionKey, options);
|
|
138
140
|
} catch (e) {
|
|
139
141
|
return emptyResult(url, regionKey, 'regional-proxy', e);
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
|
-
import
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { after, describe, it } from 'node:test';
|
|
3
6
|
|
|
4
|
-
import {
|
|
7
|
+
import { emptyResult, enableGpc, projectRoot, rulesForFrame, runTest } from '../../../lib/regional-testing/harness.mjs';
|
|
8
|
+
import { buildProxyConfig, deviceContextOptions } from './regional-proxy.mjs';
|
|
5
9
|
|
|
6
10
|
const credentials = {
|
|
7
11
|
REGIONAL_PROXY_PASSWORD: 'password',
|
|
@@ -59,3 +63,149 @@ describe('regional proxy config', () => {
|
|
|
59
63
|
assert.throws(() => buildProxyConfig('gb', { REGIONAL_PROXY_GB: 'socks4://proxy.example:1080' }), /unsupported proxy protocol/);
|
|
60
64
|
});
|
|
61
65
|
});
|
|
66
|
+
|
|
67
|
+
describe('device emulation', () => {
|
|
68
|
+
it('emulates nothing by default', () => {
|
|
69
|
+
assert.deepEqual(deviceContextOptions(), {});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('keeps the device settings but not its browser', () => {
|
|
73
|
+
const options = deviceContextOptions('iPhone SE');
|
|
74
|
+
assert.equal(options.isMobile, true);
|
|
75
|
+
assert.equal(options.hasTouch, true);
|
|
76
|
+
assert.match(options.userAgent ?? '', /iPhone/);
|
|
77
|
+
assert.equal('defaultBrowserType' in options, false);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('rejects unknown devices', () => {
|
|
81
|
+
assert.throws(() => deviceContextOptions('Nokia 3310'), /Unknown Playwright device/);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('Global Privacy Control', () => {
|
|
86
|
+
it('sends the header and sets navigator.globalPrivacyControl', async () => {
|
|
87
|
+
/** @type {{ headers: Record<string, string>[], scripts: Function[] }} */
|
|
88
|
+
const calls = { headers: [], scripts: [] };
|
|
89
|
+
const page = /** @type {any} */ ({
|
|
90
|
+
setExtraHTTPHeaders: async (/** @type {Record<string, string>} */ headers) => calls.headers.push(headers),
|
|
91
|
+
addInitScript: async (/** @type {Function} */ script) => calls.scripts.push(script),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
await enableGpc(page);
|
|
95
|
+
|
|
96
|
+
assert.deepEqual(calls.headers, [{ 'Sec-GPC': '1' }]);
|
|
97
|
+
assert.equal(calls.scripts.length, 1);
|
|
98
|
+
// Run the init script against a stand-in Navigator to check what it defines.
|
|
99
|
+
class Navigator {}
|
|
100
|
+
new Function('Navigator', `(${calls.scripts[0].toString()})()`)(Navigator);
|
|
101
|
+
assert.equal(/** @type {any} */ (new Navigator()).globalPrivacyControl, true);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The GPC headers runTest sets before navigating. The fake page fails to navigate, so the run stops there.
|
|
106
|
+
* @param {object} options
|
|
107
|
+
*/
|
|
108
|
+
async function gpcHeadersFor(options) {
|
|
109
|
+
/** @type {Record<string, string>[]} */
|
|
110
|
+
const headers = [];
|
|
111
|
+
const page = /** @type {any} */ ({
|
|
112
|
+
setExtraHTTPHeaders: async (/** @type {Record<string, string>} */ value) => headers.push(value),
|
|
113
|
+
addInitScript: async () => {},
|
|
114
|
+
goto: async () => {
|
|
115
|
+
throw new Error('no network in tests');
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
const provider = /** @type {any} */ ({ name: 'fake', defaultScreenshotsDir: '.', inject: async () => ({}) });
|
|
119
|
+
const result = await runTest(page, 'https://example.com/', 'us', options, provider);
|
|
120
|
+
assert.match(result.errors.join(' '), /no network in tests/);
|
|
121
|
+
return headers;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
it('is on by default', async () => {
|
|
125
|
+
assert.deepEqual(await gpcHeadersFor({}), [{ 'Sec-GPC': '1' }]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('is off with gpc: false', async () => {
|
|
129
|
+
assert.deepEqual(await gpcHeadersFor({ gpc: false }), []);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('rules per frame', () => {
|
|
134
|
+
/** @type {import('../../../../lib/rules.js').AutoConsentCMPRule[]} */
|
|
135
|
+
const fullRules = JSON.parse(fs.readFileSync(path.join(projectRoot, 'rules/rules.json'), 'utf-8')).autoconsent;
|
|
136
|
+
/** @param {(runContext: { main: boolean, frame: boolean, urlPattern?: string }) => boolean} test */
|
|
137
|
+
const fullRuleNames = (test) =>
|
|
138
|
+
fullRules
|
|
139
|
+
.filter((r) => test({ main: true, frame: false, ...r.runContext }))
|
|
140
|
+
.map((r) => r.name)
|
|
141
|
+
.sort();
|
|
142
|
+
/** @param {import('../../../../lib/types.js').RuleBundle} bundle */
|
|
143
|
+
const compactRuleNames = (bundle) => (bundle.compact?.r ?? []).map((r) => r[1]).sort();
|
|
144
|
+
|
|
145
|
+
it('gives a subframe only the rules that run in frames', () => {
|
|
146
|
+
const bundle = rulesForFrame('optOut', 'https://ads.example/frame', false);
|
|
147
|
+
assert.deepEqual(bundle.autoconsent, []);
|
|
148
|
+
assert.deepEqual(
|
|
149
|
+
compactRuleNames(bundle),
|
|
150
|
+
fullRuleNames((rc) => rc.frame && !rc.urlPattern),
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('gives the main frame the generic rules', () => {
|
|
155
|
+
const bundle = rulesForFrame(null, 'https://example.com/', true);
|
|
156
|
+
assert.deepEqual(
|
|
157
|
+
compactRuleNames(bundle),
|
|
158
|
+
fullRuleNames((rc) => rc.main && !rc.urlPattern),
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('gives opt-in the full rules, with their opt-in steps', () => {
|
|
163
|
+
const bundle = rulesForFrame('optIn', 'https://ads.example/frame', false);
|
|
164
|
+
assert.equal(bundle.compact, undefined);
|
|
165
|
+
assert.equal(bundle.autoconsent?.length, fullRules.length);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe('final screenshot', () => {
|
|
170
|
+
const screenshotsDir = fs.mkdtempSync(path.join(os.tmpdir(), 'regional-testing-'));
|
|
171
|
+
after(() => fs.rmSync(screenshotsDir, { recursive: true, force: true }));
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Run a test on a fake page whose screenshot succeeds, or throws a Playwright-style timeout.
|
|
175
|
+
* @param {boolean} fail
|
|
176
|
+
*/
|
|
177
|
+
async function runWithScreenshot(fail) {
|
|
178
|
+
const page = /** @type {any} */ ({
|
|
179
|
+
setExtraHTTPHeaders: async () => {},
|
|
180
|
+
addInitScript: async () => {},
|
|
181
|
+
goto: async () => {},
|
|
182
|
+
screenshot: async () => {
|
|
183
|
+
if (fail) {
|
|
184
|
+
throw new Error('page.screenshot: Timeout 30000ms exceeded.\nCall log:\n - taking page screenshot');
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
const ctx = {
|
|
189
|
+
waitForCompletion: async () => false,
|
|
190
|
+
hasMessage: () => false,
|
|
191
|
+
collectResult: (/** @type {string} */ url, /** @type {string} */ region) => emptyResult(url, region, 'regional-proxy'),
|
|
192
|
+
};
|
|
193
|
+
const provider = /** @type {any} */ ({ name: 'regional-proxy', defaultScreenshotsDir: screenshotsDir, inject: async () => ctx });
|
|
194
|
+
return runTest(page, 'https://example.com/', 'us', {}, provider);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
it('is recorded when it succeeds', async () => {
|
|
198
|
+
const result = await runWithScreenshot(false);
|
|
199
|
+
assert.deepEqual(result.screenshotPaths, [path.join(screenshotsDir, 'example.com-us-final.jpg')]);
|
|
200
|
+
assert.equal(
|
|
201
|
+
result.errors.some((e) => e.startsWith('Screenshot failed')),
|
|
202
|
+
false,
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('reports the first line of the error when it fails', async () => {
|
|
207
|
+
const result = await runWithScreenshot(true);
|
|
208
|
+
assert.deepEqual(result.screenshotPaths, []);
|
|
209
|
+
assert.ok(result.errors.includes('Screenshot failed: page.screenshot: Timeout 30000ms exceeded.'), result.errors.join('; '));
|
|
210
|
+
});
|
|
211
|
+
});
|