puppeteer#launch TypeScript Examples
The following examples show how to use
puppeteer#launch.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: puppeteerCtx.ts From mockiavelli with MIT License | 7 votes |
export function setupPuppeteerCtx() {
let browser: Browser;
const testCtx: PuppeteerTestCtx = {};
beforeAll(async () => {
browser = await launch({
headless: true,
devtools: false,
args: ['--no-sandbox'],
});
});
afterAll(async () => {
await browser.close();
});
beforeEach(async () => {
// Setup new page (tab)
testCtx.page = await browser.newPage();
await testCtx.page.goto(`http://localhost:${PORT}`);
// Instantiate
testCtx.mockiavelli = await Mockiavelli.setup(testCtx.page);
testCtx.makeRequest = makeRequestFactory(testCtx.page);
});
afterEach(async () => {
await testCtx.page.close();
});
return testCtx;
}
Example #2
Source File: start.ts From anchor-web-app with Apache License 2.0 | 6 votes |
(async () => {
// chromium debugging port
// @see https://www.jetbrains.com/help/webstorm/run-debug-configuration-node-js-remote-debug.html
// @see https://github.com/microsoft/vscode-chrome-debug#attach
const remoteDebuggingPort: number = +(process.env.INSPECT_CHROME ?? 9222);
const port: number = +(process.env.PORT ?? 3000);
const browser = await launch({
userDataDir: process.env.CHROMIUM_USER_DATA_DEBUG,
headless: false,
defaultViewport: null,
args: [
'--start-fullscreen',
`--remote-debugging-port=${remoteDebuggingPort}`,
],
ignoreDefaultArgs: ['--disable-extensions'],
devtools: true,
});
const [page] = await browser.pages();
await page.goto(`http://localhost:${port}`);
//await page.waitForFunction(
// `document.querySelector('#app h1').innerHTML === 'Hello World!'`,
// {
// timeout: 1000 * 60,
// polling: 1000 * 3,
// },
//);
})();
Example #3
Source File: puppeteer-core.module.ts From nest-puppeteer with MIT License | 5 votes |
static forRoot(
launchOptions: LaunchOptions = DEFAULT_CHROME_LAUNCH_OPTIONS,
instanceName: string = DEFAULT_PUPPETEER_INSTANCE_NAME,
): DynamicModule {
const instanceNameProvider = {
provide: PUPPETEER_INSTANCE_NAME,
useValue: instanceName,
};
const browserProvider = {
provide: getBrowserToken(instanceName),
async useFactory() {
return await launch(launchOptions);
},
};
const contextProvider = {
provide: getContextToken(instanceName),
async useFactory(browser: Browser) {
return browser.createIncognitoBrowserContext();
},
inject: [getBrowserToken(instanceName)],
};
const pageProvider = {
provide: getPageToken(instanceName),
async useFactory(context: BrowserContext) {
return await context.newPage();
},
inject: [getContextToken(instanceName)],
};
return {
module: PuppeteerCoreModule,
providers: [
instanceNameProvider,
browserProvider,
contextProvider,
pageProvider,
],
exports: [browserProvider, contextProvider, pageProvider],
};
}
Example #4
Source File: puppeteer-core.module.ts From nest-puppeteer with MIT License | 5 votes |
static forRootAsync(options: PuppeteerModuleAsyncOptions): DynamicModule {
const puppeteerInstanceName =
options.instanceName ?? DEFAULT_PUPPETEER_INSTANCE_NAME;
const instanceNameProvider = {
provide: PUPPETEER_INSTANCE_NAME,
useValue: puppeteerInstanceName,
};
const browserProvider = {
provide: getBrowserToken(puppeteerInstanceName),
async useFactory(puppeteerModuleOptions: PuppeteerModuleOptions) {
return await launch(
puppeteerModuleOptions.launchOptions ?? DEFAULT_CHROME_LAUNCH_OPTIONS,
);
},
inject: [PUPPETEER_MODULE_OPTIONS],
};
const contextProvider = {
provide: getContextToken(puppeteerInstanceName),
async useFactory(browser: Browser) {
return await browser.createIncognitoBrowserContext();
},
inject: [
PUPPETEER_MODULE_OPTIONS,
getBrowserToken(puppeteerInstanceName),
],
};
const pageProvider = {
provide: getPageToken(puppeteerInstanceName),
async useFactory(context: BrowserContext) {
return await context.newPage();
},
inject: [
PUPPETEER_MODULE_OPTIONS,
getContextToken(puppeteerInstanceName),
],
};
const asyncProviders = this.createAsyncProviders(options);
return {
module: PuppeteerCoreModule,
imports: options.imports,
providers: [
...asyncProviders,
browserProvider,
contextProvider,
pageProvider,
instanceNameProvider,
],
exports: [browserProvider, contextProvider, pageProvider],
};
}
Example #5
Source File: PuppeteerRunnerFactory.ts From double-agent with MIT License | 5 votes |
public async startFactory() {
this.browser = await launch({
headless: true,
ignoreHTTPSErrors: true,
});
}