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

Ad-blocking: DNR handle unsupported regexps #1960

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion src/background/custom-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,21 @@ async function update(text, { trustedScriptlets }) {
errors.push(...result.value.errors);
}

dnrRules.push(...result.value.rules);
for (const rule of result.value.rules) {
if (rule.condition.regexFilter) {
const { isSupported, reason } =
await chrome.declarativeNetRequest.isRegexSupported({
regex: rule.condition.regexFilter,
});
if (!isSupported) {
errors.push(
`Could not apply a custom filter as "${rule.condition.regexFilter}" is a not supported regexp due to: ${reason}`,
);
continue;
}
}
dnrRules.push(rule);
}
}

result.dnrRules = await updateDNRRules(dnrRules);
Expand Down
21 changes: 17 additions & 4 deletions src/background/exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,21 @@ async function updateFilters() {
try {
const result = (await convert(filter.toString())).rules;

rules.push(
...result.map((rule) => ({
for (const rule of result) {
if (rule.condition.regexFilter) {
const { isSupported, reason } =
await chrome.declarativeNetRequest.isRegexSupported({
regex: rule.condition.regexFilter,
});
if (!isSupported) {
console.error(
`Could not add an exception for "${tracker.name}" as filter "${filter.toString()}" is a not supported regexp due to: ${reason}`,
);
continue;
}
}

rules.push({
...rule,
condition: {
...rule.condition,
Expand Down Expand Up @@ -107,8 +120,8 @@ async function updateFilters() {
},
// Internal prefix + priority
priority: 2000000 + rule.priority,
})),
);
});
}
} catch (e) {
console.error('[exceptions] Error while converting filter:', e);
}
Expand Down