Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@ghostery/adblocker-electron
Advanced tools
Efficient
· Minimal
· JavaScript
· TypeScript
· uBlock Origin- and Easylist-compatible
Node.js
· Puppeteer
· Electron
· WebExtension
Install: npm install --save @ghostery/adblocker-electron
.
For a complete example check-out: @ghostery/adblocker-electron-example.
Creating an instance of ElectronBlocker
and start blocking ads!
import { ElectronBlocker } from '@ghostery/adblocker-electron';
import fetch from 'cross-fetch'; // required 'fetch'
ElectronBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
blocker.enableBlockingInSession(session.defaultSession);
});
You are ready to block ads!
There are other ways you can create an instance of the blocking engine to start blocking ads.
If you already have filters locally:
import { ElectronBlocker } from '@ghostery/adblocker-electron';
const blocker = ElectronBlocker.parse(fs.readFileSync('easylist.txt', 'utf-8'));
Fetching lists from URLs:
import { ElectronBlocker } from '@ghostery/adblocker-electron';
import fetch from 'cross-fetch'; // required 'fetch'
const blocker = await ElectronBlocker.fromLists(fetch, [
'https://easylist.to/easylist/easylist.txt'
]);
Use ready-made configs to block ads and optionally trackers:
import { ElectronBlocker } from '@ghostery/adblocker-electron';
import fetch from 'cross-fetch'; // required 'fetch'
let blocker = await ElectronBlocker.fromPrebuiltAdsOnly(fetch); // ads only
blocker = await ElectronBlocker.fromPrebuiltAdsAndTracking(fetch); // ads and tracking
To stop blocking ads in a session:
blocker.disableBlockingInSession(session.defaultSession);
To avoid having to create the same instance of ElectronBlocker
all over again,
you can serialize it to a byte-array which you can store on disk for faster
loading.
import { ElectronBlocker } from '@ghostery/adblocker-electron';
import fetch from 'cross-fetch'; // required 'fetch'
import { promises as fs } from 'fs'; // used for caching
ElectronBlocker.fromPrebuiltAdsAndTracking(fetch, {
path: 'engine.bin',
read: fs.readFile,
write: fs.writeFile,
}).then((blocker) => {
blocker.enableBlockingInSession(session.defaultSession);
});
Or you can do this manually to control the way caching is done:
import { ElectronBlocker } from '@ghostery/adblocker-electron';
import fetch from 'cross-fetch'; // required 'fetch'
ElectronBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
const buffer = blocker.serialize();
const restoredBlocker = ElectronBlocker.deserialize(buffer);
// `restoredBlocker` is deep-equal to `blocker`!
});
v2.0.1 (Mon Oct 21 2024)
@ghostery/adblocker-electron-preload
, @ghostery/adblocker-electron
executeJavaScript
#4278 (@nullptropy)@ghostery/adblocker
@ghostery/adblocker-webextension
@ghostery/adblocker-puppeteer
FAQs
Ghostery adblocker Electron wrapper
The npm package @ghostery/adblocker-electron receives a total of 0 weekly downloads. As such, @ghostery/adblocker-electron popularity was classified as not popular.
We found that @ghostery/adblocker-electron demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.