From 08799dd839ef716408aade7e47fdd9d6190254c0 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Mon, 31 Jul 2017 04:29:54 -0700 Subject: [PATCH] [doc] Bring back examples to page shortcut methods The motivation behind the patch: - examples are probably the most valuable thing in the doc - currently, one would need to navigate to `page.evaluate` and then click to the `frame.evaluate` to see the example. - with this patch, all the descriptions for the shortcut methods are copied as well. So there's an example for `page.evaluate` right away. Drive-by: fix links for `page.$` and `page.$$` --- docs/api.md | 94 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 12 deletions(-) diff --git a/docs/api.md b/docs/api.md index c68583baf1f..3ed8bca72d7 100644 --- a/docs/api.md +++ b/docs/api.md @@ -316,8 +316,12 @@ Emitted when a [response] is received. - `pageFunction` <[function]\([Element]\)> Function to be evaluated with first element matching `selector` - `...args` <...[string]> Arguments to pass to `pageFunction` - returns: <[Promise]<[Object]>> Promise which resolves to function return value. +Example: +```js +const outerhtml = await page.$('#box', e => e.outerHTML); +``` -Shortcut for [page.mainFrame().$(selector, pageFunction, ...args)](#pageselector-fun-args). +Shortcut for [page.mainFrame().$(selector, pageFunction, ...args)](#frameselector-pagefunction-args). #### page.$$(selector, pageFunction, ...args) @@ -326,15 +330,22 @@ Shortcut for [page.mainFrame().$(selector, pageFunction, ...args)](#pageselector - `pageFunction` <[function]\([Element]\)> Function to be evaluted for every element matching `selector`. - `...args` <...[string]> Arguments to pass to `pageFunction` - returns: <[Promise]<[Array]<[Object]>>> Promise which resolves to array of function return values. +Example: +```js +const headings = await page.$$('h1,h2,h3,h4', el => el.textContent); +for (const heading of headings) console.log(heading); +``` -Shortcut for [page.mainFrame().$$(selector, pageFunction, ...args)](#pageselector-fun-args). +Shortcut for [page.mainFrame().$$(selector, pageFunction, ...args)](#frameselector-pagefunction-args-1). #### page.addScriptTag(url) - `url` <[string]> Url of a script to be added - returns: <[Promise]> Promise which resolves as the script gets added and loads. + +Adds a `