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)
})
}
}