New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@browserless/goto

Package Overview
Dependencies
Maintainers
1
Versions
286
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@browserless/goto - npm Package Compare versions

Comparing version 5.2.5 to 5.3.0

LICENSE

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [5.3.0](https://github.com/kikobeats/browserless/tree/master/packages/goto/compare/v5.2.5...v5.3.0) (2019-04-03)
### Features
* add builtin adblock ([e370770](https://github.com/kikobeats/browserless/tree/master/packages/goto/commit/e370770))
## [5.2.5](https://github.com/kikobeats/browserless/tree/master/packages/goto/compare/v5.2.4...v5.2.5) (2019-03-10)

@@ -8,0 +19,0 @@

13

package.json

@@ -5,3 +5,3 @@ {

"homepage": "https://browserless.js.org",
"version": "5.2.5",
"version": "5.3.0",
"main": "src/index.js",

@@ -33,7 +33,8 @@ "author": {

"@browserless/devices": "^5.2.3",
"@cliqz/adblocker": "~0.8.0",
"debug": "~4.1.0",
"extract-domain": "~2.0.4",
"is-tracking-domain": "~1.1.6",
"got": "~9.6.0",
"p-timeout": "~2.0.1",
"require-one-of": "~1.0.2"
"require-one-of": "~1.0.2",
"tldts": "~4.0.5"
},

@@ -47,5 +48,7 @@ "engines": {

"scripts": {
"postinstall": "node scripts/postinstall",
"test": "exit 0"
},
"license": "MIT"
"license": "MIT",
"gitHead": "ba167f870d75ba79813e32ee0e62bdc9f3d194ab"
}
'use strict'
const { FiltersEngine, makeRequest } = require('@cliqz/adblocker')
const { getDevice } = require('@browserless/devices')
const debug = require('debug')('browserless:goto')
const extractDomain = require('extract-domain')
const tldts = require('tldts')
const path = require('path')
const fs = require('fs')
const isTracker = require('./is-tracker')
const engine = FiltersEngine.parse(fs.readFileSync(path.resolve(__dirname, './rules.txt'), 'utf-8'))
const isEmpty = val => val == null || !(Object.keys(val) || val).length
const isExternalUrl = (domainOne, domainTwo) => domainOne !== domainTwo
const types = {
document: 'main_frame',
eventsource: 'other',
fetch: 'xhr',
font: 'font',
image: 'image',
manifest: 'other',
media: 'media',
other: 'other',
script: 'script',
stylesheet: 'stylesheet',
texttrack: 'other',
websocket: 'websocket',
xhr: 'xhr'
}
/**
*
* Mapping from puppeteer request types to adblocker. This is needed because not all
* types from puppeteer have the same name as the webRequest APIs from browsers
* (which the adblocker expects).
*
* Related:
* - https://github.com/GoogleChrome/puppeteer/blob/v1.14.0/docs/api.md#requestresourcetype
* - https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/ResourceType
*/
const webRequestType = resourceType => {
const type = types[resourceType]
if (!type) throw Error(`Type ${resourceType} not mapped`)
return type
}
const WAIT_UNTIL = ['networkidle0']

@@ -20,3 +53,3 @@

device,
abortTrackers,
adblock,
abortTypes = [],

@@ -35,3 +68,2 @@ waitFor = 0,

const resourceUrl = req.url()
const resourceType = req.resourceType()

@@ -44,10 +76,20 @@

const urlDomain = extractDomain(url)
const resourceDomain = extractDomain(resourceUrl)
const isExternal = isExternalUrl(urlDomain, resourceDomain)
if (adblock) {
const { match: isMatch } = engine.match(
makeRequest(
{
type: webRequestType(resourceType),
sourceUrl: req.frame().url(),
url: resourceUrl
},
url => tldts.parse(url)
)
)
if (abortTrackers && isExternal && isTracker(resourceDomain)) {
debug(`abort:tracker:${++reqCount.abort}`, resourceUrl)
return req.abort()
if (isMatch) {
debug(`abort:tracker:${++reqCount.abort}`, resourceUrl)
return req.abort()
}
}
debug(`continue:${resourceType}:${++reqCount.continue}`, resourceUrl)

@@ -54,0 +96,0 @@ return req.continue()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc