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

chore: update adblocker and use pre-built engine from CDN #134

Merged
merged 2 commits into from Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/goto/package.json
Expand Up @@ -29,7 +29,7 @@
],
"dependencies": {
"@browserless/devices": "^5.18.5",
"@cliqz/adblocker-puppeteer": "~1.4.1",
"@cliqz/adblocker-puppeteer": "~1.5.0",
"debug-logfmt": "~1.0.4",
"got": "~9.6.0",
"p-reflect": "~2.1.0",
Expand Down
24 changes: 13 additions & 11 deletions packages/goto/scripts/postinstall.js
@@ -1,6 +1,6 @@
'use strict'

const { PuppeteerBlocker, fullLists } = require('@cliqz/adblocker-puppeteer')
const { PuppeteerBlocker } = require('@cliqz/adblocker-puppeteer')
const { promisify } = require('util')
const got = require('got')
const fs = require('fs')
Expand All @@ -9,20 +9,22 @@ const writeFile = promisify(fs.writeFile)

const OUTPUT_FILENAME = 'src/engine.bin'

// Lightweight `fetch` polyfill on top of `got` to allow consumption by adblocker
const fetch = async url => {
const body = (await got(url)).body
// Small helpers to allow fetching different types of data with `got`
const fetchBuffer = async url => (await got(url, { encoding: null })).body
const fetchText = async url => Buffer.from(await fetchBuffer(url), 'ascii')
const fetchJson = async url => JSON.parse(await fetchText(url))

return {
text: () => body,
arrayBuffer: () => Buffer.from(body, 'ascii').buffer,
json: () => JSON.parse(body)
}
}
// Lightweight `fetch` polyfill on top of `got` to allow consumption by adblocker
const fetch = url =>
Promise.resolve({
text: () => fetchText(url),
arrayBuffer: () => fetchBuffer(url),
json: () => fetchJson(url)
})

const main = async () => {
// create a ad-blocker engine
const engine = await PuppeteerBlocker.fromLists(fetch, fullLists)
const engine = await PuppeteerBlocker.fromPrebuiltFull(fetch)
await writeFile(OUTPUT_FILENAME, engine.serialize())
}

Expand Down