本文整理汇总了TypeScript中puppeteer.launch函数的典型用法代码示例。如果您正苦于以下问题:TypeScript launch函数的具体用法?TypeScript launch怎么用?TypeScript launch使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了launch函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: launch
t.test('switch account not needed', async t => {
const browser = await launch(PUPPETEER_LAUNCH_OPTIONS)
const page = await browser.newPage()
await page.setContent('<h1>ok</h1>')
const clicked = await bridge.clickSwitchAccount(page)
await page.close()
await browser.close()
t.equal(clicked, false, 'should no button found')
})
示例2:
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
page.setDefaultTimeout(100000);
await page.goto("https://news.ycombinator.com", { waitUntil: "networkidle0" });
await page.pdf({ path: "hn.pdf", format: "A4" });
const frame = page.frames()[0];
await frame.goto('/');
browser.close();
})();
示例3: async
b: async () => {
const browser = await puppet.launch()
const page = await browser.newPage()
await page.goto('https://example.com/')
// await page.screenshot({path: 'example.png'})
const abc = await page.title()
ok(abc === 'Example Domain')
await browser.close()
}
示例4: beforeAll
beforeAll( async () => {
browser = await puppeteer.launch( { headless: true } );
page = await browser.newPage();
// Print errors from the page
page.on( 'console', ( msg: any ) => console.log( 'PAGE LOG:', msg.text() ) );
page.on( 'pageerror', ( err: Error ) => console.error( err ) );
await page.goto( `file://${__dirname}/test-browser-umd.html`, {
waitUntil: 'load'
} );
} );
示例5:
(async () => {
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
]
});
const page = await browser.newPage();
await page.goto("https://example.com");
await page.screenshot({ path: "example.png" });
browser.close();
})();
示例6:
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://example.com");
const base64string: string = await page.screenshot({ encoding: "base64" });
const buffer: Buffer = await page.screenshot({ encoding: "binary" });
const screenshotOptions: puppeteer.ScreenshotOptions = {
fullPage: true,
};
const stringOrBuffer: string | Buffer = await page.screenshot(screenshotOptions);
browser.close();
})();
示例7: before
before(async () => {
this.browser = await puppeteer.launch({
defaultViewport: {
width: 1920,
height: 1080,
},
headless: false,
args: ['--no-sandbox'],
});
const bundlePath = path.resolve(__dirname, '../dist/rrweb.min.js');
this.code = fs.readFileSync(bundlePath, 'utf8');
});