Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
before(() => {
prevEnvHeadless = process.env[ENV_VARS.HEADLESS];
process.env[ENV_VARS.HEADLESS] = '1';
// Find free port for the proxy
return portastic.find({ min: 50000, max: 50100 }).then((ports) => {
return new Promise((resolve, reject) => {
const httpServer = http.createServer();
// Setup proxy authorization
httpServer.authenticate = function (req, fn) {
// parse the "Proxy-Authorization" header
const auth = req.headers['proxy-authorization'];
if (!auth) {
// optimization: don't invoke the child process if no
// "Proxy-Authorization" header was given
// console.log('not Proxy-Authorization');
return fn(null, false);
}
before(() => {
prevEnvHeadless = process.env[ENV_VARS.HEADLESS];
process.env[ENV_VARS.HEADLESS] = '1';
// Find free port for the proxy
return portastic.find({ min: 50000, max: 50100 }).then((ports) => {
return new Promise((resolve, reject) => {
const httpServer = http.createServer();
// Setup proxy authorization
httpServer.authenticate = function (req, fn) {
// parse the "Proxy-Authorization" header
const auth = req.headers['proxy-authorization'];
if (!auth) {
// optimization: don't invoke the child process if no
// "Proxy-Authorization" header was given
// console.log('not Proxy-Authorization');
return fn(null, false);
after(() => {
log.setLevel(logLevel);
process.env[ENV_VARS.HEADLESS] = prevEnvHeadless;
});
before(() => {
prevEnvHeadless = process.env[ENV_VARS.HEADLESS];
process.env[ENV_VARS.HEADLESS] = '1';
logLevel = log.getLevel();
log.setLevel(log.LEVELS.ERROR);
});
before(() => {
logLevel = log.getLevel();
log.setLevel(log.LEVELS.ERROR);
prevEnvHeadless = process.env[ENV_VARS.HEADLESS];
process.env[ENV_VARS.HEADLESS] = '1';
});
before(async () => {
prevEnvHeadless = process.env[ENV_VARS.HEADLESS];
process.env[ENV_VARS.HEADLESS] = '1';
if (!fs.existsSync(TEST_ACTORS_FOLDER)) fs.mkdirSync(TEST_ACTORS_FOLDER);
process.chdir(TEST_ACTORS_FOLDER);
});
after(async () => {
process.env[ENV_VARS.HEADLESS] = prevEnvHeadless;
process.chdir('../');
if (fs.existsSync(TEST_ACTORS_FOLDER)) await rimrafPromised(TEST_ACTORS_FOLDER);
});
before(() => {
logLevel = log.getLevel();
log.setLevel(log.LEVELS.ERROR);
prevEnvHeadless = process.env[ENV_VARS.HEADLESS];
process.env[ENV_VARS.HEADLESS] = '1';
});
export const getDefaultBrowseOptions = () => {
return {
headless: process.env[ENV_VARS.HEADLESS] === '1' && process.env[ENV_VARS.XVFB] !== '1',
browserName: 'chrome',
proxyUrl: null,
userAgent: null,
};
};
checkParamOrThrow(options.stealthOptions, 'options.stealthOptions', 'Maybe Object');
if (options.useApifyProxy && options.proxyUrl) throw new Error('Cannot combine "options.useApifyProxy" with "options.proxyUrl"!');
if (options.liveView || options.liveViewOptions) {
log.deprecated('Live view is no longer available in Apify.launchPuppeteer() and launchPuppeteerOptions. '
+ 'Use options.useLiveView in PuppeteerPool for an updated version. '
+ 'For live view with Apify.launchPuppeteer(), use Apify.LiveViewServer.');
}
const puppeteer = getPuppeteerOrThrow(options.puppeteerModule);
const optsCopy = Object.assign({}, options);
optsCopy.args = optsCopy.args || [];
optsCopy.args.push('--no-sandbox');
if (optsCopy.headless == null) {
optsCopy.headless = process.env[ENV_VARS.HEADLESS] === '1' && process.env[ENV_VARS.XVFB] !== '1';
}
if (optsCopy.useChrome && (optsCopy.executablePath === undefined || optsCopy.executablePath === null)) {
optsCopy.executablePath = process.env[ENV_VARS.CHROME_EXECUTABLE_PATH] || getTypicalChromeExecutablePath();
}
if (optsCopy.useApifyProxy) {
optsCopy.proxyUrl = getApifyProxyUrl({
groups: optsCopy.apifyProxyGroups,
session: optsCopy.apifyProxySession,
groupsParamName: 'options.apifyProxyGroups',
sessionParamName: 'options.apifyProxySession',
});
}
if (optsCopy.defaultViewport === undefined) {
optsCopy.defaultViewport = LAUNCH_PUPPETEER_DEFAULT_VIEWPORT;
}