puppeteer: Upgrade typings for version 0.13

This commit is contained in:
Knuppe
2017-11-12 21:43:47 -02:00
parent 6a2ea9f633
commit e4aa247252
2 changed files with 705 additions and 34 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -13,7 +13,7 @@ import * as puppeteer from "puppeteer";
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://news.ycombinator.com", { waitUntil: "networkidle" });
await page.goto("https://news.ycombinator.com", { waitUntil: "networkidle0" });
await page.pdf({ path: "hn.pdf", format: "A4" });
browser.close();
@@ -99,7 +99,7 @@ puppeteer.launch().then(async browser => {
await page.emulateMedia("screen");
await page.pdf({ path: "page.pdf" });
await page.setRequestInterceptionEnabled(true);
await page.setRequestInterception(true);
page.on("request", interceptedRequest => {
if (
interceptedRequest.url.endsWith(".png") ||
@@ -151,7 +151,8 @@ puppeteer.launch().then(async browser => {
});
const inputElement = await page.$("input[type=submit]");
await inputElement.click();
if (inputElement)
await inputElement.click();
});
// Example with launch options
@@ -182,8 +183,14 @@ puppeteer.launch().then(async browser => {
const div = await page.$("#myDiv");
const input = await page.$("#myInput");
if (!button)
throw new Error('Unable to select myButton');
if (!input)
throw new Error('Unable to select myInput');
await page.addStyleTag({
url: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
url: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
});
console.log(page.url());
@@ -214,7 +221,7 @@ puppeteer.launch().then(async browser => {
await page.deleteCookie(...await page.cookies());
const metrics = page.getMetrics();
const metrics = await page.metrics();
console.log(metrics.Documents, metrics.Frames, metrics.JSEventListeners);
const navResponse = await page.waitForNavigation({
@@ -224,11 +231,12 @@ puppeteer.launch().then(async browser => {
// evaluate example
const bodyHandle = await page.$('body');
const html = await page.evaluate(body => body.innerHTML, bodyHandle);
await bodyHandle.dispose();
if (bodyHandle) {
const html = await page.evaluate(body => body.innerHTML, bodyHandle);
await bodyHandle.dispose();
}
// getProperties example
const handle = await page.evaluateHandle(() => ({window, document}));
const handle = await page.evaluateHandle(() => ({ window, document }));
const properties = await handle.getProperties();
const windowHandle = properties.get('window');
const documentHandle = properties.get('document');