diff --git a/lib/eval-snippets.ts b/lib/eval-snippets.ts index 9f4099bf2c..778a22d8eb 100644 --- a/lib/eval-snippets.ts +++ b/lib/eval-snippets.ts @@ -186,6 +186,26 @@ export const snippets = { .split('=')[1], ), ).purposes.a === false), + EVAL_SHOPIFY_POLARIS_OPT_OUT: () => { + const root = document.querySelector('#polaris-css-lockdown-container')?.shadowRoot; + if (!root) return false; + const declineButton = Array.from(root.querySelectorAll('button')).find((button) => button.textContent?.trim() === 'Decline'); + const acknowledgeButton = Array.from(root.querySelectorAll('button')).find((button) => button.textContent?.trim() === 'Okay'); + const oneClickOptOut = root.querySelector('[data-polaris-one-click-opt-out="true"], [data-testid="oneClickOptOutLink"]'); + const optOut = declineButton || oneClickOptOut || acknowledgeButton; + if (!optOut) return false; + optOut.click(); + return true; + }, + EVAL_SHOPIFY_POLARIS_TEST: () => { + const settingsCookie = document.cookie + .split(';') + .find((s) => s.trim().startsWith('polaris_consent_settings')) + ?.split('=')[1]; + if (!settingsCookie) return false; + const settings = JSON.parse(decodeURIComponent(settingsCookie)); + return settings.adsPermitted === false && settings.notOptedOut === false; + }, EVAL_SKYSCANNER_TEST: () => document.cookie.match(/gdpr=[^;]*adverts:::false/) && !document.cookie.match(/gdpr=[^;]*init:::true/), EVAL_SIRDATA_UNBLOCK_SCROLL: () => { document.documentElement.classList.forEach((cls) => { diff --git a/rules/autoconsent/shopify-polaris.json b/rules/autoconsent/shopify-polaris.json new file mode 100644 index 0000000000..2081d2e2de --- /dev/null +++ b/rules/autoconsent/shopify-polaris.json @@ -0,0 +1,43 @@ +{ + "name": "shopify-polaris", + "vendorUrl": "https://shopify.dev/docs/api/customer-privacy", + "cosmetic": false, + "prehideSelectors": ["#polaris-css-lockdown-container"], + "detectCmp": [ + { + "exists": ["#polaris-css-lockdown-container", ".polaris-consent-widget"] + } + ], + "detectPopup": [ + { + "visible": ["#polaris-css-lockdown-container", ".polaris-consent-widget"] + } + ], + "optIn": [ + { + "waitForThenClick": [ + "#polaris-css-lockdown-container", + "[role=\"region\"][aria-label=\"Cookie consent\"] .polaris-consent-widget__actions button:last-child" + ], + "timeout": 5000 + } + ], + "optOut": [ + { + "wait": 1000 + }, + { + "eval": "EVAL_SHOPIFY_POLARIS_OPT_OUT" + }, + { + "waitForThenClick": ["#polaris-css-lockdown-container", "[data-testid=\"oneClickOptOutClose\"]"], + "timeout": 5000, + "optional": true + } + ], + "test": [ + { + "eval": "EVAL_SHOPIFY_POLARIS_TEST" + } + ] +} diff --git a/tests/shopify-polaris.spec.ts b/tests/shopify-polaris.spec.ts new file mode 100644 index 0000000000..26b4291faf --- /dev/null +++ b/tests/shopify-polaris.spec.ts @@ -0,0 +1,4 @@ +import generateCMPTests from '../playwright/runner'; + +generateCMPTests('shopify-polaris', ['https://www.mcgeeandco.com/products/calvert-brass-tissue-box-cover']); +generateCMPTests('shopify-polaris', ['https://mightyvault.com/'], { testSelfTest: false });