Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should complain if an option arg key is of the wrong type', () => {
// $ExpectError string is incompatible with boolean in property `ignoreHTTPSErrors`
puppeteer.connect({ ignoreHTTPSErrors: 'testing...' });
});
it('should preserve Browser type', () => {
async function main() {
let info;
while (!info) {
info = await attempt();
}
const browser = await puppeteer.connect({
browserWSEndpoint: info.webSocketDebuggerUrl
});
const pages = await browser.pages();
const page = pages[0];
page.evaluate(`
window.top.chromeScreenshot = async function(options = {}) {
const response = await fetch(
"http://localhost:${port}/screenshot" +
"?rand=" + Math.random().toString(36) +
"&options=" + encodeURIComponent(JSON.stringify(options)) +
"&secret=${encodeURIComponent(secret)}"
);
const base64 = await response.text();
return base64;
};
`);
async setup() {
await super.setup();
const browserWSEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8');
if (!browserWSEndpoint) {
throw new Error('wsEndpoint not found');
}
this.global.BROWSER = await puppeteer.connect({
browserWSEndpoint,
});
}
};
async setup() {
console.log('Setup Test Environment.');
await super.setup();
const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8');
if (!wsEndpoint) {
throw new Error('wsEndpoint not found');
}
this.global.__METRICS__ = loadMetricsData();
this.global.__BROWSER__ = await puppeteer.connect({
browserWSEndpoint: wsEndpoint,
})
}
static async init(config) {
const maxConcurrency = (config.maxConcurrency !== undefined) ? config.maxConcurrency : 10;
let puppeteer_browser;
let browserLaunched;
if(config.browserURL !== undefined) {
puppeteer_browser = await Puppeteer.connect({
browserURL: config.browserURL
});
browserLaunched = false;
} else if(config.browserWSEndpoint !== undefined) {
puppeteer_browser = await Puppeteer.connect({
browserWSEndpoint: config.browserWSEndpoint
});
browserLaunched = false;
} else {
puppeteer_browser = await Puppeteer.launch({
headless: config.headless,
args: ['--disable-web-security']
});
browserLaunched = true;
async launchBrowser({
headless = true,
existingWebSocketUri,
disableSandbox = false,
executablePath = null,
useDocker = true
} = {}) {
if (existingWebSocketUri) {
this.isUsingDocker = useDocker;
this.browser = await puppeteer.connect({
browserWSEndpoint: existingWebSocketUri
});
return this.browser;
}
if (useDocker) {
const webSocketUri = await dockerRunChromium();
this.browser = await puppeteer.connect({
browserWSEndpoint: webSocketUri
});
this.isUsingDocker = useDocker;
} else {
const launchConfig = {
async connect(options) {
try {
this.prefixedLogger.log('Launching browser...');
this.browser = await puppeteer.connect(options);
this.testConfig.newWindow = true;
} catch (error) {
this._logError(error);
throw new Error('Failed to launch the browser');
}
return this.browser;
}
async connectBrowser(options) {
if (!this.browser) {
logger.log('Launching browser...');
try {
this.browser = await puppeteer.connect(options);
} catch (error) {
logger.trace(error);
}
} else {
logger.log('Using existing browser instance');
}
}