diff --git a/packages/goto/package.json b/packages/goto/package.json index 00e93c66e1..021355279c 100644 --- a/packages/goto/package.json +++ b/packages/goto/package.json @@ -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", diff --git a/packages/goto/scripts/postinstall.js b/packages/goto/scripts/postinstall.js index 6ee193d72d..bc9364f955 100644 --- a/packages/goto/scripts/postinstall.js +++ b/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') @@ -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()) }