Skip to content

Commit

Permalink
chore: Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
berstend committed Nov 24, 2019
1 parent f10ddcd commit 226bab6
Show file tree
Hide file tree
Showing 76 changed files with 4,290 additions and 4,333 deletions.
7 changes: 4 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": [
"standard"
]
"extends": ["prettier-standard"],
"rules": {
"lines-between-class-members": "off"
}
}
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"prettier-config-standard"
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ yarn lerna add fs-extra --scope=puppeteer-extra-plugin-user-data-dir

# Remove dependency
# https://github.com/lerna/lerna/issues/833
yarn lerna exec -- yarn remove fs-extra
yarn lerna exec 'yarn remove fs-extra; echo 0'

# Run test in all packages
yarn test
Expand All @@ -51,4 +51,8 @@ yarn lerna bootstrap

# Update deps within packages (interactive)
yarn lernaupdate

# If in doubt :-(
yarn lerna exec "rm -f yarn.lock; rm -rf node_modules; echo 0"
rm -f yarn.lock && rm -rf node_modules && yarn cache clean
```
5 changes: 1 addition & 4 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"lerna": "2.11.0",
"packages": [
"packages/*"
],
"packages": ["packages/*"],
"version": "independent",
"useWorkspaces": true,
"npmClient": "yarn",
Expand Down
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,22 @@
"packages/*"
],
"devDependencies": {
"eslint": "^6.7.0",
"eslint-config-prettier": "^6.7.0",
"eslint-config-prettier-standard": "^3.0.1",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"lerna": "^3.19.0",
"lerna-update-wizard": "^0.17.4"
"lerna-update-wizard": "^0.17.4",
"prettier": "^1.19.1",
"prettier-config-standard": "^1.0.1"
},
"resolutions": {
"**/fsevents": "^1.2.9"
"**/fsevents": "^2.1.2"
},
"dependencies": {}
}
10 changes: 5 additions & 5 deletions packages/puppeteer-extra-plugin-anonymize-ua/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ const { PuppeteerExtraPlugin } = require('puppeteer-extra-plugin')
* const browser = await puppeteer.launch()
*/
class Plugin extends PuppeteerExtraPlugin {
constructor (opts = {}) {
constructor(opts = {}) {
super(opts)
}

get name () {
get name() {
return 'anonymize-ua'
}

get defaults () {
get defaults() {
return {
stripHeadless: true,
makeWindows: true,
customFn: null
}
}

async onPageCreated (page) {
async onPageCreated(page) {
let ua = await page.browser().userAgent()
if (this.opts.stripHeadless) {
ua = ua.replace('HeadlessChrome/', 'Chrome/')
Expand All @@ -54,6 +54,6 @@ class Plugin extends PuppeteerExtraPlugin {
}
}

module.exports = function (pluginConfig) {
module.exports = function(pluginConfig) {
return new Plugin(pluginConfig)
}
10 changes: 5 additions & 5 deletions packages/puppeteer-extra-plugin-anonymize-ua/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

const PLUGIN_NAME = 'anonymize-ua'

const { test } = require('ava')
const test = require('ava')

const Plugin = require('.')

test('is a function', async (t) => {
test('is a function', async t => {
t.is(typeof Plugin, 'function')
})

test('should have the basic class members', async (t) => {
test('should have the basic class members', async t => {
const instance = new Plugin()

t.is(instance.name, PLUGIN_NAME)
t.true(instance._isPuppeteerExtraPlugin)
})

test('should have the public child class members', async (t) => {
test('should have the public child class members', async t => {
const instance = new Plugin()
const prototype = Object.getPrototypeOf(instance)
const childClassMembers = Object.getOwnPropertyNames(prototype)
Expand All @@ -29,7 +29,7 @@ test('should have the public child class members', async (t) => {
t.true(childClassMembers.length === 4)
})

test('should have opts with default values', async (t) => {
test('should have opts with default values', async t => {
const instance = new Plugin()
const opts = instance.opts

Expand Down
9 changes: 4 additions & 5 deletions packages/puppeteer-extra-plugin-anonymize-ua/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "MIT",
"scripts": {
"docs": "update-markdown-jsdoc",
"test": "ava -v && standard",
"test": "ava -v && eslint --ext .js .",
"test-ci": "yarn test"
},
"engines": {
Expand All @@ -25,13 +25,12 @@
"pupeteer"
],
"devDependencies": {
"ava": "^0.25.0",
"puppeteer": "next",
"standard": "^11.0.0",
"ava": "~2.4.0",
"puppeteer": "^2.0.0",
"update-markdown-jsdoc": "^1.0.2"
},
"dependencies": {
"debug": "^3.1.0",
"debug": "^4.1.1",
"puppeteer-extra-plugin": "^3.0.4"
},
"gitHead": "72fe830c158f1e971c8499fdd5232338dd53c220"
Expand Down
52 changes: 20 additions & 32 deletions packages/puppeteer-extra-plugin-anonymize-ua/test/headless.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('ava')
const test = require('ava')

const PUPPETEER_ARGS = ['--no-sandbox', '--disable-setuid-sandbox']

Expand All @@ -10,13 +10,16 @@ test.beforeEach(t => {
delete require.cache[require.resolve('puppeteer-extra-plugin-anonymize-ua')]
})

test('will remove headless from the user-agent', async (t) => {
test('will remove headless from the user-agent', async t => {
const puppeteer = require('puppeteer-extra')
puppeteer.use(require('puppeteer-extra-plugin-anonymize-ua')())
const AnonymizeUA = require('puppeteer-extra-plugin-anonymize-ua')()
puppeteer.use(AnonymizeUA)

const browser = await puppeteer.launch({ args: PUPPETEER_ARGS })
const page = await browser.newPage()
await page.goto('https://httpbin.org/headers', {waitUntil: 'domcontentloaded'})
await page.goto('https://httpbin.org/headers', {
waitUntil: 'domcontentloaded'
})

const content = await page.content()
t.true(content.includes('Windows NT 10.0'))
Expand All @@ -26,7 +29,7 @@ test('will remove headless from the user-agent', async (t) => {
t.true(true)
})

test('will remove headless from the user-agent in incognito page', async (t) => {
test('will remove headless from the user-agent in incognito page', async t => {
const puppeteer = require('puppeteer-extra')
puppeteer.use(require('puppeteer-extra-plugin-anonymize-ua')())

Expand All @@ -36,7 +39,9 @@ test('will remove headless from the user-agent in incognito page', async (t) =>
if (browser.createIncognitoBrowserContext) {
const context = await browser.createIncognitoBrowserContext()
const page = await context.newPage()
await page.goto('https://httpbin.org/headers', {waitUntil: 'domcontentloaded'})
await page.goto('https://httpbin.org/headers', {
waitUntil: 'domcontentloaded'
})

const content = await page.content()
t.true(content.includes('Windows NT 10.0'))
Expand All @@ -47,15 +52,19 @@ test('will remove headless from the user-agent in incognito page', async (t) =>
t.true(true)
})

test('will use a custom fn to modify the user-agent', async (t) => {
test('will use a custom fn to modify the user-agent', async t => {
const puppeteer = require('puppeteer-extra')
puppeteer.use(require('puppeteer-extra-plugin-anonymize-ua')({
customFn: (ua) => 'MyCoolAgent/' + ua.replace('Chrome', 'Beer')
}))
puppeteer.use(
require('puppeteer-extra-plugin-anonymize-ua')({
customFn: ua => 'MyCoolAgent/' + ua.replace('Chrome', 'Beer')
})
)

const browser = await puppeteer.launch({ args: PUPPETEER_ARGS })
const page = await browser.newPage()
await page.goto('https://httpbin.org/headers', {waitUntil: 'domcontentloaded'})
await page.goto('https://httpbin.org/headers', {
waitUntil: 'domcontentloaded'
})

const content = await page.content()
t.true(content.includes('Windows NT 10.0'))
Expand All @@ -66,24 +75,3 @@ test('will use a custom fn to modify the user-agent', async (t) => {
await browser.close()
t.true(true)
})

test('will not modify the user-agent when disabled', async (t) => {
const puppeteer = require('puppeteer-extra')
puppeteer.use(require('puppeteer-extra-plugin-anonymize-ua')({
stripHeadless: false,
makeWindows: false,
customFn: null
}))

const browser = await puppeteer.launch({ args: PUPPETEER_ARGS })
const page = await browser.newPage()
await page.goto('https://httpbin.org/headers', {waitUntil: 'domcontentloaded'})

const content = await page.content()
t.true(content.includes('HeadlessChrome'))
t.true(!content.includes('MyCoolAgent/Mozilla'))
t.true(!content.includes('Beer/'))

await browser.close()
t.true(true)
})
35 changes: 35 additions & 0 deletions packages/puppeteer-extra-plugin-anonymize-ua/test/headless_off.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict'

const test = require('ava')

const PUPPETEER_ARGS = ['--no-sandbox', '--disable-setuid-sandbox']

test.beforeEach(t => {
// Make sure we work with pristine modules
delete require.cache[require.resolve('puppeteer-extra')]
delete require.cache[require.resolve('puppeteer-extra-plugin-anonymize-ua')]
})

test('will not modify the user-agent when disabled', async t => {
const puppeteer = require('puppeteer-extra')
const AnonymizeUA = require('puppeteer-extra-plugin-anonymize-ua')({
stripHeadless: false,
makeWindows: false,
customFn: null
})
puppeteer.use(AnonymizeUA)

const browser = await puppeteer.launch({ args: PUPPETEER_ARGS })
const page = await browser.newPage()
await page.goto('https://httpbin.org/headers', {
waitUntil: 'domcontentloaded'
})

const content = await page.content()
t.true(content.includes('HeadlessChrome'))
t.true(!content.includes('MyCoolAgent/Mozilla'))
t.true(!content.includes('Beer/'))

await browser.close()
t.true(true)
})
10 changes: 4 additions & 6 deletions packages/puppeteer-extra-plugin-anonymize-ua/test/popup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const { test } = require('ava')
const test = require('ava')

const PUPPETEER_ARGS = ['--no-sandbox', '--disable-setuid-sandbox']

const waitEvent = function (emitter, eventName) {
const waitEvent = function(emitter, eventName) {
return new Promise(resolve => emitter.once(eventName, resolve))
}

Expand All @@ -14,14 +14,12 @@ test.beforeEach(t => {
delete require.cache[require.resolve('puppeteer-extra-plugin-anonymize-ua')]
})

test('known issue: will not remove headless from implicitly created popup pages', async (t) => {
test('known issue: will not remove headless from implicitly created popup pages', async t => {
const puppeteer = require('puppeteer-extra')
puppeteer.use(require('puppeteer-extra-plugin-anonymize-ua')())
const browser = await puppeteer.launch({ args: PUPPETEER_ARGS })

const pages = await Promise.all(
[...Array(10)].map(slot => browser.newPage())
)
const pages = await Promise.all([...Array(10)].map(slot => browser.newPage()))
for (const page of pages) {
// Works
const ua = await page.evaluate(() => window.navigator.userAgent)
Expand Down
18 changes: 7 additions & 11 deletions packages/puppeteer-extra-plugin-anonymize-ua/test/stresstest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('ava')
const test = require('ava')

const PUPPETEER_ARGS = ['--no-sandbox', '--disable-setuid-sandbox']

Expand All @@ -10,7 +10,7 @@ test.beforeEach(t => {
delete require.cache[require.resolve('puppeteer-extra-plugin-anonymize-ua')]
})

test('will remove headless from the user-agent on multiple browsers', async (t) => {
test('will remove headless from the user-agent on multiple browsers', async t => {
const puppeteer = require('puppeteer-extra')
puppeteer.use(require('puppeteer-extra-plugin-anonymize-ua')())
const browser = await puppeteer.launch({ args: PUPPETEER_ARGS })
Expand All @@ -29,14 +29,12 @@ test('will remove headless from the user-agent on multiple browsers', async (t)
t.true(true)
})

test('will remove headless from the user-agent on many pages', async (t) => {
test('will remove headless from the user-agent on many pages', async t => {
const puppeteer = require('puppeteer-extra')
puppeteer.use(require('puppeteer-extra-plugin-anonymize-ua')())
const browser = await puppeteer.launch({ args: PUPPETEER_ARGS })

const pages = await Promise.all(
[...Array(30)].map(slot => browser.newPage())
)
const pages = await Promise.all([...Array(30)].map(slot => browser.newPage()))
for (const page of pages) {
const ua = await page.evaluate(() => window.navigator.userAgent)
t.true(ua.includes('Windows NT 10.0'))
Expand All @@ -47,7 +45,7 @@ test('will remove headless from the user-agent on many pages', async (t) => {
t.true(true)
})

test('will remove headless from the user-agent on many incognito pages', async (t) => {
test('will remove headless from the user-agent on many incognito pages', async t => {
const puppeteer = require('puppeteer-extra')
puppeteer.use(require('puppeteer-extra-plugin-anonymize-ua')())
const browser = await puppeteer.launch({ args: PUPPETEER_ARGS })
Expand All @@ -69,7 +67,7 @@ test('will remove headless from the user-agent on many incognito pages', async (
t.true(true)
})

test('will remove headless from the user-agent on many pages in parallel', async (t) => {
test('will remove headless from the user-agent on many pages in parallel', async t => {
const puppeteer = require('puppeteer-extra')
puppeteer.use(require('puppeteer-extra-plugin-anonymize-ua')())
const browser = await puppeteer.launch({ args: PUPPETEER_ARGS })
Expand All @@ -80,9 +78,7 @@ test('will remove headless from the user-agent on many pages in parallel', async
t.true(ua.includes('Windows NT 10.0'))
t.true(!ua.includes('HeadlessChrome'))
}
await Promise.all(
[...Array(30)].map(slot => testCase())
)
await Promise.all([...Array(30)].map(slot => testCase()))

await browser.close()
t.true(true)
Expand Down
Loading

0 comments on commit 226bab6

Please sign in to comment.