Skip to content

Commit

Permalink
docs: update examples to use import
Browse files Browse the repository at this point in the history
Closes #8821
  • Loading branch information
OrKoN committed Dec 9, 2022
1 parent 9b86dc4 commit f8d1fde
Show file tree
Hide file tree
Showing 24 changed files with 46 additions and 45 deletions.
4 changes: 2 additions & 2 deletions docs/api/puppeteer.browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The constructor for this class is marked as internal. Third-party code should no
An example of using a [Browser](./puppeteer.browser.md) to create a [Page](./puppeteer.page.md):
```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
Expand All @@ -40,7 +40,7 @@ const puppeteer = require('puppeteer');
An example of disconnecting from and reconnecting to a [Browser](./puppeteer.browser.md):
```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The constructor for this class is marked as internal. Third-party code should no
## Example

```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.elementhandle.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export declare class ElementHandle<ElementType extends Node = Element> extends J
ElementHandles can be created with the [Page.$()](./puppeteer.page._.md) method.
```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.elementhandle.waitforselector.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Throws if an element matching the given selector doesn't appear.
## Example

```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.elementhandle.waitforxpath.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sidebar_label: ElementHandle.waitForXPath
> This method works across navigation.
>
> ```ts
> const puppeteer = require('puppeteer');
> import puppeteer from 'puppeteer';
> (async () => {
> const browser = await puppeteer.launch();
> const page = await browser.newPage();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.frame.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ At any point in time, [pages](./puppeteer.page.md) expose their current frame tr
An example of dumping frame tree:

```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.frame.waitforfunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ the promise which resolve when the `pageFunction` returns a truthy value.
The `waitForFunction` can be used to observe viewport size change:

```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

(async () => {
. const browser = await puppeteer.launch();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.frame.waitforselector.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Throws if an element matching the given selector doesn't appear.
## Example

```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.page.emulatevisiondeficiency.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Promise&lt;void&gt;
## Example

```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
Expand Down
8 changes: 4 additions & 4 deletions docs/api/puppeteer.page.exposefunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Promise&lt;void&gt;
An example of adding an `md5` function into the page:

```ts
const puppeteer = require('puppeteer');
const crypto = require('crypto');
import puppeteer from 'puppeteer';
import crypto from 'crypto';

(async () => {
const browser = await puppeteer.launch();
Expand All @@ -70,8 +70,8 @@ const crypto = require('crypto');
An example of adding a `window.readfile` function into the page:

```ts
const puppeteer = require('puppeteer');
const fs = require('fs');
import puppeteer from 'puppeteer';
import fs from 'fs';

(async () => {
const browser = await puppeteer.launch();
Expand Down
6 changes: 3 additions & 3 deletions docs/api/puppeteer.page.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The constructor for this class is marked as internal. Third-party code should no
This example creates a page, navigates it to a URL, and then saves a screenshot:
```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
Expand Down Expand Up @@ -157,7 +157,7 @@ page.off('request', logRequest);
| [waitForSelector(selector, options)](./puppeteer.page.waitforselector.md) | | <p>Wait for the <code>selector</code> to appear in page. If at the moment of calling the method the <code>selector</code> already exists, the method will return immediately. If the <code>selector</code> doesn't appear after the <code>timeout</code> milliseconds of waiting, the function will throw.</p><p>This method works across navigations:</p> |
```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
Expand All @@ -181,7 +181,7 @@ const puppeteer = require('puppeteer');
| [waitForXPath(xpath, options)](./puppeteer.page.waitforxpath.md) | | <p>Wait for the <code>xpath</code> to appear in page. If at the moment of calling the method the <code>xpath</code> already exists, the method will return immediately. If the <code>xpath</code> doesn't appear after the <code>timeout</code> milliseconds of waiting, the function will throw.</p><p>This method works across navigation</p>
```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.page.setrequestinterception.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Promise&lt;void&gt;
An example of a naïve request interceptor that aborts all image requests:

```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.page.waitforfunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Promise&lt;[HandleFor](./puppeteer.handlefor.md)&lt;Awaited&lt;ReturnType&lt;Fun
The [Page.waitForFunction()](./puppeteer.page.waitforfunction.md) can be used to observe viewport size change:

```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.page.waitforselector.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Wait for the `selector` to appear in page. If at the moment of calling the metho
This method works across navigations:

```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.page.waitforxpath.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Wait for the `xpath` to appear in page. If at the moment of calling the method t
This method works across navigation

```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
Expand Down
2 changes: 1 addition & 1 deletion docs/api/puppeteer.puppeteernode.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The constructor for this class is marked as internal. Third-party code should no
The following is a typical example of using Puppeteer to drive automation:
```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
Expand Down
5 changes: 3 additions & 2 deletions docs/guides/chrome-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ The following is code for getting a handle to the
an extension whose source is located in `./my-extension`:

```ts
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';
import path from 'path';

(async () => {
const pathToExtension = require('path').join(__dirname, 'my-extension');
const pathToExtension = path.join(process.cwd(), 'my-extension');
const browser = await puppeteer.launch({
headless: 'chrome',
args: [
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/request-interception.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ continued, responded or aborted.
An example of a naïve request interceptor that aborts all image requests:

```js
const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
Expand Down
4 changes: 2 additions & 2 deletions packages/puppeteer-core/src/api/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const enum BrowserEmittedEvents {
* An example of using a {@link Browser} to create a {@link Page}:
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
*
* (async () => {
* const browser = await puppeteer.launch();
Expand All @@ -196,7 +196,7 @@ export const enum BrowserEmittedEvents {
* An example of disconnecting from and reconnecting to a {@link Browser}:
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
*
* (async () => {
* const browser = await puppeteer.launch();
Expand Down
20 changes: 10 additions & 10 deletions packages/puppeteer-core/src/api/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export interface PageEventObject {
* This example creates a page, navigates it to a URL, and then saves a screenshot:
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
*
* (async () => {
* const browser = await puppeteer.launch();
Expand Down Expand Up @@ -636,7 +636,7 @@ export class Page extends EventEmitter {
* An example of a naïve request interceptor that aborts all image requests:
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
* (async () => {
* const browser = await puppeteer.launch();
* const page = await browser.newPage();
Expand Down Expand Up @@ -1161,8 +1161,8 @@ export class Page extends EventEmitter {
* An example of adding an `md5` function into the page:
*
* ```ts
* const puppeteer = require('puppeteer');
* const crypto = require('crypto');
* import puppeteer from 'puppeteer';
* import crypto from 'crypto';
*
* (async () => {
* const browser = await puppeteer.launch();
Expand All @@ -1185,8 +1185,8 @@ export class Page extends EventEmitter {
* An example of adding a `window.readfile` function into the page:
*
* ```ts
* const puppeteer = require('puppeteer');
* const fs = require('fs');
* import puppeteer from 'puppeteer';
* import fs from 'fs';
*
* (async () => {
* const browser = await puppeteer.launch();
Expand Down Expand Up @@ -1865,7 +1865,7 @@ export class Page extends EventEmitter {
* @example
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
*
* (async () => {
* const browser = await puppeteer.launch();
Expand Down Expand Up @@ -2371,7 +2371,7 @@ export class Page extends EventEmitter {
* This method works across navigations:
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
* (async () => {
* const browser = await puppeteer.launch();
* const page = await browser.newPage();
Expand Down Expand Up @@ -2431,7 +2431,7 @@ export class Page extends EventEmitter {
* This method works across navigation
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
* (async () => {
* const browser = await puppeteer.launch();
* const page = await browser.newPage();
Expand Down Expand Up @@ -2491,7 +2491,7 @@ export class Page extends EventEmitter {
* The {@link Page.waitForFunction} can be used to observe viewport size change:
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
* (async () => {
* const browser = await puppeteer.launch();
* const page = await browser.newPage();
Expand Down
2 changes: 1 addition & 1 deletion packages/puppeteer-core/src/common/Dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {Protocol} from 'devtools-protocol';
* @example
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
*
* (async () => {
* const browser = await puppeteer.launch();
Expand Down
6 changes: 3 additions & 3 deletions packages/puppeteer-core/src/common/ElementHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const applyOffsetsToQuad = (
* ElementHandles can be created with the {@link Page.$} method.
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
*
* (async () => {
* const browser = await puppeteer.launch();
Expand Down Expand Up @@ -296,7 +296,7 @@ export class ElementHandle<
* @example
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
*
* (async () => {
* const browser = await puppeteer.launch();
Expand Down Expand Up @@ -356,7 +356,7 @@ export class ElementHandle<
* This method works across navigation.
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
* (async () => {
* const browser = await puppeteer.launch();
* const page = await browser.newPage();
Expand Down
6 changes: 3 additions & 3 deletions packages/puppeteer-core/src/common/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export interface FrameAddStyleTagOptions {
* An example of dumping frame tree:
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
*
* (async () => {
* const browser = await puppeteer.launch();
Expand Down Expand Up @@ -569,7 +569,7 @@ export class Frame {
* @example
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
*
* (async () => {
* const browser = await puppeteer.launch();
Expand Down Expand Up @@ -647,7 +647,7 @@ export class Frame {
* The `waitForFunction` can be used to observe viewport size change:
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
*
* (async () => {
* . const browser = await puppeteer.launch();
Expand Down
2 changes: 1 addition & 1 deletion packages/puppeteer-core/src/node/PuppeteerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface PuppeteerLaunchOptions
* The following is a typical example of using Puppeteer to drive automation:
*
* ```ts
* const puppeteer = require('puppeteer');
* import puppeteer from 'puppeteer';
*
* (async () => {
* const browser = await puppeteer.launch();
Expand Down

0 comments on commit f8d1fde

Please sign in to comment.