How to use @cliqz/adblocker-webextension - 2 common examples

To help you get started, we’ve selected a few @cliqz/adblocker-webextension examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cliqz-oss / adblocker / packages / adblocker-webextension-example / background.ts View on Github external
});
}

function incrementBlockedCounter(request: Request, blockingResponse: BlockingResponse): void {
  updateBlockedCounter(request.tabId, {
    incr: Boolean(blockingResponse.match),
    reset: request.isMainFrame(),
  });
}

// Whenever the active tab changes, then we update the count of blocked request
chrome.tabs.onActivated.addListener(({ tabId }: chrome.tabs.TabActiveInfo) =>
  updateBlockedCounter(tabId),
);

WebExtensionBlocker.fromLists(fetch, fullLists, {
  enableCompression: true,
  enableHtmlFiltering: true,
}).then((blocker: WebExtensionBlocker) => {
  blocker.enableBlockingInBrowser();
  blocker.on('request-blocked', incrementBlockedCounter);
  blocker.on('request-redirected', incrementBlockedCounter);

  blocker.on('csp-injected', (request: Request) => {
    console.log('csp', request.url);
  });

  blocker.on('script-injected', (script: string, url: string) => {
    console.log('script', script.length, url);
  });

  blocker.on('style-injected', (style: string, url: string) => {
github remusao / blockrz / background.ts View on Github external
// Whenever the active tab changes, then we update the count of blocked request
chrome.tabs.onActivated.addListener(({ tabId }: chrome.tabs.TabActiveInfo) =>
  updateBlockedCounter(tabId),
);

// Reset counter if tab is reloaded
chrome.tabs.onUpdated.addListener((tabId, { status }) => {
  if (status === 'loading') {
    updateBlockedCounter(tabId, {
      incr: false,
      reset: true,
    });
  }
});

WebExtensionBlocker.fromPrebuiltAdsAndTracking().then((blocker: WebExtensionBlocker) => {
  blocker.enableBlockingInBrowser();
  blocker.on('request-blocked', incrementBlockedCounter);
  blocker.on('request-redirected', incrementBlockedCounter);

  blocker.on('csp-injected', (directives, request: Request) => {
    console.log('csp', directives, request.url);
  });

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

@cliqz/adblocker-webextension

Ghostery adblocker WebExtension wrapper

MPL-2.0
Latest version published 23 days ago

Package Health Score

48 / 100
Full package analysis

Similar packages