Merge pull request #21463 from knuppe/master

puppeteer: Upgrade typings for version 0.13
This commit is contained in:
Nathan Shively-Sanders
2017-11-14 08:20:41 -08:00
committed by GitHub
2 changed files with 699 additions and 30 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") ||
@@ -150,8 +150,8 @@ puppeteer.launch().then(async browser => {
browser.close();
});
const inputElement = await page.$("input[type=submit]");
if (inputElement) await inputElement.click();
const inputElement = (await page.$("input[type=submit]"))!;
await inputElement.click();
});
// Example with launch options
@@ -182,8 +182,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 +220,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({
@@ -228,7 +234,7 @@ puppeteer.launch().then(async browser => {
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');