diff --git a/assets/cookie-notice/frontconsent-cookie-notice.js b/assets/cookie-notice/frontconsent-cookie-notice.js index 27fba1c..d5f66a7 100644 --- a/assets/cookie-notice/frontconsent-cookie-notice.js +++ b/assets/cookie-notice/frontconsent-cookie-notice.js @@ -69,7 +69,13 @@ function purgeTrackingCookies() { var patterns = Array.isArray(frcnCookieNotice.purgeCookies) ? frcnCookieNotice.purgeCookies : []; - if (!patterns.length || !document.cookie) { + if (!patterns.length) { + return; + } + + purgeTrackingStorage(patterns); + + if (!document.cookie) { return; } @@ -94,6 +100,41 @@ }); } + /** + * Same purge for localStorage/sessionStorage: some tags keep their + * identifiers there instead of (or as well as) in cookies — e.g. the + * OpenAI ChatGPT Ads pixel's `oaiq_cs:` session entry. + * Storage access can throw (blocked site data, private windows), so each + * store is handled on its own and failures are ignored. + * + * @param {string[]} patterns Purge patterns (see purgeTrackingCookies()). + */ + function purgeTrackingStorage(patterns) { + ['localStorage', 'sessionStorage'].forEach(function (storeName) { + try { + var store = window[storeName]; + + if (!store) { + return; + } + + var keys = []; + + for (var i = 0; i < store.length; i++) { + keys.push(store.key(i)); + } + + keys.forEach(function (key) { + if (key && matchesPurgePattern(key, patterns)) { + store.removeItem(key); + } + }); + } catch (e) { + // Storage unavailable: nothing to purge. + } + }); + } + function defineActivateGatedHelper() { window.frcnCookieNoticeActivateGated = window.frcnCookieNoticeActivateGated || function (allowedCategories) { if (allowedCategories && !allowedCategories.analytics) { diff --git a/assets/cookie-notice/frontconsent-cookie-notice.min.js b/assets/cookie-notice/frontconsent-cookie-notice.min.js index 2a75fa2..270edcf 100644 --- a/assets/cookie-notice/frontconsent-cookie-notice.min.js +++ b/assets/cookie-notice/frontconsent-cookie-notice.min.js @@ -1 +1 @@ -!function(){"use strict";function e(e){var o=document.cookie.match(new RegExp("(?:^|; )"+e+"=([^;]*)"));if(!o)return"";try{return decodeURIComponent(o[1])}catch(e){return""}}function o(){var e=Array.isArray(frcnCookieNotice.purgeCookies)?frcnCookieNotice.purgeCookies:[];if(e.length&&document.cookie){for(var o=(window.location&&window.location.hostname?window.location.hostname:"").split("."),n=[""],t=0;t Array.from(cookies.jar.values()).map((cookie) => cookie.name), reopenListeners }; + return { actionListeners, cookieNames: () => Array.from(cookies.jar.values()).map((cookie) => cookie.name), reopenListeners, sessionStorage }; } test('rejecting deletes tracking cookies set on the host and on parent domains', () => { @@ -157,3 +170,26 @@ test('withdrawing an earlier acceptance deletes tracking cookies', () => { assert.deepEqual(environment.cookieNames(), []); }); + +test('withdrawing an earlier acceptance also deletes the ChatGPT Ads pixel cookie and storage entry', () => { + const environment = createEnvironment( + [ + ['frcn_cookie_consent', 'accepted', ''], + ['__obref', 'abc', ''] + ], + { 'oaiq_cs:PIXEL123': '1', unrelated: 'keep' } + ); + + environment.reopenListeners.click(); + + assert.deepEqual(environment.cookieNames(), []); + assert.deepEqual(environment.sessionStorage.keys(), ['unrelated']); +}); + +test('rejecting clears tracking entries kept in web storage', () => { + const environment = createEnvironment([], { 'oaiq_cs:PIXEL123': '1', unrelated: 'keep' }); + + environment.actionListeners.reject({ preventDefault() {} }); + + assert.deepEqual(environment.sessionStorage.keys(), ['unrelated']); +});