Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict'
const { PuppeteerBlocker } = require('@cliqz/adblocker-puppeteer')
const debug = require('debug-logfmt')('browserless:goto')
const createDevices = require('@browserless/devices')
const { getDomain } = require('tldts')
const pReflect = require('p-reflect')
const pTimeout = require('p-timeout')
const path = require('path')
const fs = require('fs')
const engine = PuppeteerBlocker.deserialize(
new Uint8Array(fs.readFileSync(path.resolve(__dirname, './engine.bin')))
)
engine.on('request-blocked', ({ url }) => debug('adblock:block', url))
engine.on('request-redirected', ({ url }) => debug('adblock:redirect', url))
const isEmpty = val => val == null || !(Object.keys(val) || val).length
const parseCookies = (url, str) => {
const domain = `.${getDomain(url)}`
return str.split(';').reduce((acc, str) => {
const [name, value] = str.split('=')
const cookie = {
name: name.trim(),
value,
domain,
private async loadFromCache(): Promise {
if (!this.opts.useCache) {
throw new Error('caching disabled')
}
this.debug('load from cache', this.engineCacheFile)
return PuppeteerBlocker.deserialize(
new Uint8Array(await fs.readFile(this.engineCacheFile))
)
}