Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCPA fix for Sourcepoint #302

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/cmps/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export default class AutoConsentCMPBase implements AutoCMP {
}

const snippetSrc = getFunctionBody(snippet);
enableLogs && console.log('async eval:', snippetId, snippetSrc);
return requestEval(snippetSrc).catch((e) => {
enableLogs && console.error('error evaluating rule', snippetId, e);
return false;
Expand Down
14 changes: 9 additions & 5 deletions lib/cmps/sourcepoint-frame.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { enableLogs } from "../config";
import { click, elementExists, wait, waitForElement } from "../rule-executors";
import { click, elementExists, wait, waitForElement, waitForThenClick } from "../rule-executors";
import { RunContext } from "../rules";
import { waitFor } from "../utils";
import AutoConsentCMPBase from "./base";
Expand Down Expand Up @@ -38,7 +38,7 @@ export default class SourcePoint extends AutoConsentCMPBase {
this.ccpaPopup = true;
return true;
}
return (url.pathname === '/index.html' || url.pathname === '/privacy-manager/index.html')
return (url.pathname === '/index.html' || url.pathname === '/privacy-manager/index.html' || url.pathname === '/ccpa_pm/index.html')
&& (url.searchParams.has('message_id') || url.searchParams.has('requestUUID') || url.searchParams.has('consentUUID'));
}

Expand All @@ -50,7 +50,7 @@ export default class SourcePoint extends AutoConsentCMPBase {
return await waitForElement('.priv-save-btn', 2000);
}
// check for the paywall button, and bail if it exists to prevent broken opt out
await waitForElement(".sp_choice_type_11,.sp_choice_type_12,.sp_choice_type_13,.sp_choice_type_ACCEPT_ALL", 2000);
await waitForElement(".sp_choice_type_11,.sp_choice_type_12,.sp_choice_type_13,.sp_choice_type_ACCEPT_ALL,.sp_choice_type_SAVE_AND_EXIT", 2000);
return !elementExists('.sp_choice_type_9');
}

Expand All @@ -67,7 +67,7 @@ export default class SourcePoint extends AutoConsentCMPBase {
}

isManagerOpen() {
return location.pathname === "/privacy-manager/index.html";
return location.pathname === "/privacy-manager/index.html" || location.pathname === '/ccpa_pm/index.html';
}

async optOut() {
Expand Down Expand Up @@ -104,6 +104,10 @@ export default class SourcePoint extends AutoConsentCMPBase {
}

await waitForElement('.type-modal', 20000);

// check "Do Not Sell" (CCPA) toggle if it exists
waitForThenClick('.ccpa-stack .pm-switch[aria-checked=true] .slider', 500, true); // the UI is reversed: "unchecked" switch displays as an enabled toggle

// reject all button is offered by some sites
try {
const rejectSelector1 = '.sp_choice_type_REJECT_ALL';
Expand All @@ -127,7 +131,7 @@ export default class SourcePoint extends AutoConsentCMPBase {
} catch (e) {
enableLogs && console.warn(e);
}
// TODO: race condition: the popup disappears very quickly, so the background script may not receive a success report.
// TODO: race condition: if the reject button was clicked, the popup disappears very quickly, so the background script may not receive a success report.
return click('.sp_choice_type_SAVE_AND_EXIT');
}
}
1 change: 1 addition & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// TODO: make this configurable through DevTools (and possibly toggleable per rule step type)
export const enableLogs = false; // change this to enable debug logs
2 changes: 1 addition & 1 deletion lib/rule-executors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function elementVisible(selector: ElementSelector, check: VisibilityCheck
export function waitForElement(selector: ElementSelector, timeout = 10000): Promise<boolean> {
const interval = 200;
const times = Math.ceil((timeout) / interval);
// enableLogs && console.log("[waitFor]", ruleStep.waitFor);
enableLogs && console.log("[waitForElement]", selector);
return waitFor(
() => elementSelector(selector).length > 0,
times,
Expand Down
3 changes: 1 addition & 2 deletions lib/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export default class AutoConsent {
declarativeRules.autoconsent.forEach((ruleset) => {
this.addDeclarativeCMP(ruleset);
});
enableLogs && console.log("added rules", this.rules);
}

addDeclarativeCMP(ruleset: AutoConsentCMPRule) {
Expand Down Expand Up @@ -397,7 +396,7 @@ export default class AutoConsent {
}

async receiveMessageCallback(message: BackgroundMessage) {
if (enableLogs && ['evalResp', 'report'].includes(message.type) /* evals are noisy */) {
if (enableLogs && !['evalResp', 'report'].includes(message.type) /* evals are noisy */) {
console.log('received from background', message, window.location.href);
}
switch (message.type) {
Expand Down
1 change: 1 addition & 0 deletions tests/sourcepoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import generateCMPTests from "../playwright/runner";
generateCMPTests('Sourcepoint-frame', [
'https://www.theguardian.com/',
'https://news.sky.com/',
'https://www.economist.com/',
]);

generateCMPTests('Sourcepoint-frame', [
Expand Down