Skip to content

Commit

Permalink
filter-matched emit exceptions (#6)
Browse files Browse the repository at this point in the history
* filter-match new interface; getHTMLFilters refactor

* Fixed unhide lookup

* Update getHTMLFilters return type

* Update getCSPDirectives

* matchAll: don't emit filter-matched

* Update match

* update getCosmeticFilters

* fix tests

* Cleanup

* Cleanup
  • Loading branch information
chrmod authored Jul 4, 2024
1 parent 4494b5a commit f22c78b
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 297 deletions.
16 changes: 2 additions & 14 deletions packages/adblocker-electron-example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ import fetch from 'cross-fetch';
import { app, BrowserWindow } from 'electron';
import { readFileSync, writeFileSync } from 'fs';

import {
CosmeticFilter,
ElectronBlocker,
fullLists,
NetworkFilter,
Request,
} from '@cliqz/adblocker-electron';
import { MatchingContext } from '@cliqz/adblocker';
import { ElectronBlocker, fullLists, Request } from '@cliqz/adblocker-electron';

function getUrlToLoad(): string {
let url = 'https://google.com';
Expand Down Expand Up @@ -76,12 +69,7 @@ async function createWindow() {
console.log('style', style.length, url);
});

blocker.on(
'filter-matched',
(filter: CosmeticFilter | NetworkFilter, context: MatchingContext) => {
console.log('filter-matched', filter, context);
},
);
blocker.on('filter-matched', console.log.bind(console, 'filter-matched'));

mainWindow.loadURL(getUrlToLoad());
mainWindow.webContents.openDevTools();
Expand Down
7 changes: 1 addition & 6 deletions packages/adblocker-playwright-example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ import * as pw from 'playwright';
console.log('style', url, style.length);
});

blocker.on(
'filter-matched',
(filter: CosmeticFilter | NetworkFilter, context: MatchingContext) => {
console.log('filter-matched', filter, context);
},
);
blocker.on('filter-matched', console.log.bind(console, 'filter-matched'));

await page.goto('https://www.mangareader.net/');
await page.screenshot({ path: 'output.png' });
Expand Down
10 changes: 1 addition & 9 deletions packages/adblocker-webextension-example/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ import { browser } from 'webextension-polyfill-ts';

import {
BlockingResponse,
CosmeticFilter,
fullLists,
HTMLSelector,
NetworkFilter,
Request,
WebExtensionBlocker,
} from '@cliqz/adblocker-webextension';
import { MatchingContext } from '@cliqz/adblocker';

/**
* Keep track of number of network requests altered for each tab
Expand Down Expand Up @@ -101,12 +98,7 @@ WebExtensionBlocker.fromLists(fetch, fullLists, {
console.log('style', url, style.length);
});

blocker.on(
'filter-matched',
(filter: CosmeticFilter | NetworkFilter, context: MatchingContext) => {
console.log('filter-matched', filter, context);
},
);
blocker.on('filter-matched', console.log.bind(console, 'filter-matched'));

console.log('Ready to roll!');
});
Loading

0 comments on commit f22c78b

Please sign in to comment.