Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async open (url) {
if (!url) {
throw new Error('invalid arguments')
}
const result = {}
const userAgent = await RandomHttpUserAgent.get()
const browser = await puppeteer.launch(_.get(this._options, 'puppeteer'))
const page = await browser.newPage()
await page.setUserAgent(userAgent)
page.on('console', (consoleMessage) => {
if (!result.console) {
result.console = []
}
result.console.push({ type: consoleMessage.type(), text: consoleMessage.text() })
})
await page.goto(url)
result.elements = await page.evaluate(() => {
.then(() => {
const url = buildUrl(clientId, redirectUri, options)
return RandomHttpUserAgent.get()
.then((userAgent) => this._perseverance.exec(() => doLogin.bind(this)(url, redirectUri, userAgent)))
})
}
authorizeApp (email, password, url) {
Logger.debug('Started authorizing app in Facebook')
return RandomUserAgent.get()
.then((userAgent) => this._authorizeAppCircuitBreaker.exec(email, password, url, userAgent))
.finally(() => Logger.debug('Finished authorizing app in Facebook'))
}
}
get (url, headers = {}, tor = false) {
if (!url) {
return Promise.reject(new Error('invalid arguments'))
}
const options = { url }
if (tor) {
const agentClass = _.startsWith(url, 'https') ? require('socks5-https-client/lib/Agent') : require('socks5-http-client/lib/Agent')
const agentOptions = this._options.socks
_.merge(options, { agentClass, agentOptions })
}
return RandomUserAgent.get()
.then((userAgent) => {
options.headers = _.assign({}, headers, { 'User-Agent': userAgent })
return this._request.getAsync(options)
})
}
}
constructor (options = {}) {
this._options = _.defaults(options, defaultOptions)
this._request = Promise.promisifyAll(request.defaults(this._options.request))
RandomUserAgent.configure({ maxAge: 600000, preFetch: true })
}
constructor () {
this._options = _.defaultsDeep({}, defaultOptions)
RandomHttpUserAgent.configure(_.get(this._options, 'random-http-useragent'))
}
constructor (options = {}) {
this._options = _.defaultsDeep({}, options, defaultOptions)
this._perseverance = new Perseverance(_.get(this._options, 'perseverance'))
RandomHttpUserAgent.configure(_.get(this._options, 'random-http-useragent'))
}