Skip to content
Draft
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
11 changes: 8 additions & 3 deletions post-processing/generate-autoconsent-rules/generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,12 @@ function generateRulesForSite(region, initialUrl, finalUrl, collectorResult, mat
const reviewNotes = [];
let keptCount = 0;

const llmConfirmedPopups = collectorResult.scrapedFrames.flatMap((frame) => frame.potentialPopups).filter((popup) => popup.llmMatch);
if (llmConfirmedPopups.length > 1 || llmConfirmedPopups[0].rejectButtons.length > 1) {
// const llmConfirmedPopups = collectorResult.scrapedFrames.flatMap((frame) => frame.potentialPopups).filter((popup) => popup.llmMatch);
const regexConfirmedPopups = collectorResult.scrapedFrames
.flatMap((frame) => frame.potentialPopups)
.filter((popup) => popup.regexMatch);
// if (llmConfirmedPopups.length > 1 || llmConfirmedPopups[0].rejectButtons.length > 1) {
if (regexConfirmedPopups.length > 1 || regexConfirmedPopups[0].rejectButtons.length > 1) {
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block assumes regexConfirmedPopups is non-empty (accessing regexConfirmedPopups[0]) based on an earlier guard in the caller; add an explicit guard or an assertion here to make the dependency clear, and consider passing the already-filtered list from the caller instead of recomputing it to avoid duplicated logic.

Suggested change
if (regexConfirmedPopups.length > 1 || regexConfirmedPopups[0].rejectButtons.length > 1) {
if (regexConfirmedPopups.length > 1 || (regexConfirmedPopups.length > 0 && regexConfirmedPopups[0].rejectButtons.length > 1)) {

Copilot uses AI. Check for mistakes.
console.warn('Multiple cookie popups or reject buttons found in', initialUrl);
reviewNotes.push({
needsReview: false, // it's not a problem by itself, unless this leads to multiple _rules_ generated, but we check that separately.
Expand All @@ -261,7 +265,8 @@ function generateRulesForSite(region, initialUrl, finalUrl, collectorResult, mat

// go over all frames, all confirmed popups within them, and all reject buttons inside
for (const frame of collectorResult.scrapedFrames) {
for (const popup of frame.potentialPopups.filter((p) => p.llmMatch)) {
// for (const popup of frame.potentialPopups.filter((p) => p.llmMatch)) {
for (const popup of frame.potentialPopups.filter((p) => p.regexMatch)) {
for (const button of popup.rejectButtons) {
if (ruleForButtonExists(button, matchingRules, newRules, rulesToOverride)) {
// if there is an existing rule with the same reject button, do nothing
Expand Down
34 changes: 24 additions & 10 deletions post-processing/generate-autoconsent-rules/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,21 @@ async function processCookiePopupsForSite(globalParams, { finalUrl, initialUrl,

const updatedExistingRules = structuredClone(existingRules);

const llmConfirmedPopups = collectorResult.scrapedFrames.flatMap((frame) => frame.potentialPopups).filter((popup) => popup.llmMatch);
// const llmConfirmedPopups = collectorResult.scrapedFrames.flatMap((frame) => frame.potentialPopups).filter((popup) => popup.llmMatch);
const regexConfirmedPopups = collectorResult.scrapedFrames
.flatMap((frame) => frame.potentialPopups)
.filter((popup) => popup.regexMatch);

// shortcut if no popups with llmMatch
if (llmConfirmedPopups.length === 0) {
// if (llmConfirmedPopups.length === 0) {
if (regexConfirmedPopups.length === 0) {
return { newRuleFiles, updatedRuleFiles, keptCount: 0, reviewNotes: [], updatedExistingRules };
}

const matchingRules = findMatchingExistingRules(initialUrl, finalUrl, collectorResult, existingRules);
console.log(
`Detected ${llmConfirmedPopups.length} unhandled cookie popup(s) on ${finalUrl} (matched ${matchingRules.length} existing rules)`,
// `Detected ${llmConfirmedPopups.length} unhandled cookie popup(s) on ${finalUrl} (matched ${matchingRules.length} existing rules)`,
`Detected ${regexConfirmedPopups.length} unhandled cookie popup(s) on ${finalUrl} (matched ${matchingRules.length} existing rules)`,
);
const { newRules, rulesToOverride, reviewNotes, keptCount } = generateRulesForSite(
region,
Expand Down Expand Up @@ -309,26 +314,33 @@ async function processFiles(globalParams, existingRules) {
totalSitesWithPopups++;

const matchedRules = collectorResult.cmps.map((cmp) => cmp.name.trim()).filter((name) => name !== '');
const llmConfirmedPopups = collectorResult.scrapedFrames
// const llmConfirmedPopups = collectorResult.scrapedFrames
// .flatMap((frame) => frame.potentialPopups)
// .filter((popup) => popup.llmMatch);
const regexConfirmedPopups = collectorResult.scrapedFrames
.flatMap((frame) => frame.potentialPopups)
.filter((popup) => popup.llmMatch);
.filter((popup) => popup.regexMatch);
const screenshot = jsonData.data.screenshots;

if (hasKnownCmp(collectorResult.cmps)) {
totalSitesWithKnownCmps++;
autoconsentManifest.set(fileName, {
siteUrl: jsonData.finalUrl,
matchedRules,
llmConfirmedPopups,
// llmConfirmedPopups,
regexConfirmedPopups,
screenshot,
newlyCreatedRules: [],
updatedRules: [],
reviewNotes: [],
});
} else {
const llmConfirmedPopups = collectorResult.scrapedFrames
// const llmConfirmedPopups = collectorResult.scrapedFrames
// .flatMap((frame) => frame.potentialPopups)
// .filter((popup) => popup.llmMatch);
const regexConfirmedPopups = collectorResult.scrapedFrames
.flatMap((frame) => frame.potentialPopups)
.filter((popup) => popup.llmMatch);
.filter((popup) => popup.regexMatch);
/** @type {import('./types').AutoconsentManifestFileData[]} */
let newRuleFiles = [];
/** @type {import('./types').AutoconsentManifestFileData[]} */
Expand All @@ -337,7 +349,8 @@ async function processFiles(globalParams, existingRules) {
/** @type {import('./types').ReviewNote[]} */
let reviewNotes = [];

if (llmConfirmedPopups.length > 0) {
// if (llmConfirmedPopups.length > 0) {
if (regexConfirmedPopups.length > 0) {
totalUnhandled++;
const result = await processCookiePopupsForSite(globalParams, {
finalUrl: jsonData.finalUrl,
Expand All @@ -351,7 +364,8 @@ async function processFiles(globalParams, existingRules) {
autoconsentManifest.set(fileName, {
siteUrl: jsonData.finalUrl,
matchedRules,
llmConfirmedPopups,
// llmConfirmedPopups,
regexConfirmedPopups,
screenshot,
newlyCreatedRules: newRuleFiles,
updatedRules: updatedRuleFiles,
Expand Down
3 changes: 2 additions & 1 deletion post-processing/generate-autoconsent-rules/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
* @typedef {{
* siteUrl: string;
* matchedRules: string[];
* llmConfirmedPopups: PopupData[];
* _llmConfirmedPopups?: PopupData[];
* regexConfirmedPopups: PopupData[];
* screenshot: string;
* newlyCreatedRules: AutoconsentManifestFileData[];
* updatedRules: AutoconsentManifestFileData[];
Expand Down