diff --git a/docs/api/puppeteer.frame.md b/docs/api/puppeteer.frame.md index 92d480e371d..f2bed31d82c 100644 --- a/docs/api/puppeteer.frame.md +++ b/docs/api/puppeteer.frame.md @@ -103,5 +103,4 @@ console.log(text); | [waitForFunction(pageFunction, options, args)](./puppeteer.frame.waitforfunction.md) | | | | [waitForNavigation(options)](./puppeteer.frame.waitfornavigation.md) | |

Waits for the frame to navigate. It is useful for when you run code which will indirectly cause the frame to navigate.

Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is considered a navigation.

| | [waitForSelector(selector, options)](./puppeteer.frame.waitforselector.md) | |

Waits for an element matching the given selector to appear in the frame.

This method works across navigations.

| -| [waitForTimeout(milliseconds)](./puppeteer.frame.waitfortimeout.md) | | | | [waitForXPath(xpath, options)](./puppeteer.frame.waitforxpath.md) | | | diff --git a/docs/api/puppeteer.frame.waitfortimeout.md b/docs/api/puppeteer.frame.waitfortimeout.md deleted file mode 100644 index fd3a2339086..00000000000 --- a/docs/api/puppeteer.frame.waitfortimeout.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -sidebar_label: Frame.waitForTimeout ---- - -# Frame.waitForTimeout() method - -> Warning: This API is now obsolete. -> -> Replace with `new Promise(r => setTimeout(r, milliseconds));`. -> -> Causes your script to wait for the given number of milliseconds. - -#### Signature: - -```typescript -class Frame { - waitForTimeout(milliseconds: number): Promise; -} -``` - -## Parameters - -| Parameter | Type | Description | -| ------------ | ------ | ----------------------------------- | -| milliseconds | number | the number of milliseconds to wait. | - -**Returns:** - -Promise<void> - -## Remarks - -It's generally recommended to not wait for a number of seconds, but instead use [Frame.waitForSelector()](./puppeteer.frame.waitforselector.md), [Frame.waitForXPath()](./puppeteer.frame.waitforxpath.md) or [Frame.waitForFunction()](./puppeteer.frame.waitforfunction.md) to wait for exactly the conditions you want. - -## Example - -Wait for 1 second: - -```ts -await frame.waitForTimeout(1000); -``` diff --git a/docs/api/puppeteer.page.md b/docs/api/puppeteer.page.md index 2bf44b56188..a2c4242dc0b 100644 --- a/docs/api/puppeteer.page.md +++ b/docs/api/puppeteer.page.md @@ -161,6 +161,5 @@ page.off('request', logRequest); | [waitForRequest(urlOrPredicate, options)](./puppeteer.page.waitforrequest.md) | | | | [waitForResponse(urlOrPredicate, options)](./puppeteer.page.waitforresponse.md) | | | | [waitForSelector(selector, options)](./puppeteer.page.waitforselector.md) | | Wait for the selector to appear in page. If at the moment of calling the method the selector already exists, the method will return immediately. If the selector doesn't appear after the timeout milliseconds of waiting, the function will throw. | -| [waitForTimeout(milliseconds)](./puppeteer.page.waitfortimeout.md) | | | | [waitForXPath(xpath, options)](./puppeteer.page.waitforxpath.md) | | Wait for the xpath to appear in page. If at the moment of calling the method the xpath already exists, the method will return immediately. If the xpath doesn't appear after the timeout milliseconds of waiting, the function will throw. | | [workers()](./puppeteer.page.workers.md) | | All of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) associated with the page. | diff --git a/docs/api/puppeteer.page.waitfortimeout.md b/docs/api/puppeteer.page.waitfortimeout.md deleted file mode 100644 index 681bf8a7249..00000000000 --- a/docs/api/puppeteer.page.waitfortimeout.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -sidebar_label: Page.waitForTimeout ---- - -# Page.waitForTimeout() method - -> Warning: This API is now obsolete. -> -> Replace with `new Promise(r => setTimeout(r, milliseconds));`. -> -> Causes your script to wait for the given number of milliseconds. - -#### Signature: - -```typescript -class Page { - waitForTimeout(milliseconds: number): Promise; -} -``` - -## Parameters - -| Parameter | Type | Description | -| ------------ | ------ | ----------------------------------- | -| milliseconds | number | the number of milliseconds to wait. | - -**Returns:** - -Promise<void> - -## Remarks - -It's generally recommended to not wait for a number of seconds, but instead use [Frame.waitForSelector()](./puppeteer.frame.waitforselector.md), [Frame.waitForXPath()](./puppeteer.frame.waitforxpath.md) or [Frame.waitForFunction()](./puppeteer.frame.waitforfunction.md) to wait for exactly the conditions you want. - -## Example - -Wait for 1 second: - -```ts -await page.waitForTimeout(1000); -``` diff --git a/packages/puppeteer-core/src/api/Frame.ts b/packages/puppeteer-core/src/api/Frame.ts index 757ec872c6b..99065b12a4e 100644 --- a/packages/puppeteer-core/src/api/Frame.ts +++ b/packages/puppeteer-core/src/api/Frame.ts @@ -1151,32 +1151,6 @@ export abstract class Frame extends EventEmitter { await handle.type(text, options); } - /** - * @deprecated Replace with `new Promise(r => setTimeout(r, milliseconds));`. - * - * Causes your script to wait for the given number of milliseconds. - * - * @remarks - * It's generally recommended to not wait for a number of seconds, but instead - * use {@link Frame.waitForSelector}, {@link Frame.waitForXPath} or - * {@link Frame.waitForFunction} to wait for exactly the conditions you want. - * - * @example - * - * Wait for 1 second: - * - * ```ts - * await frame.waitForTimeout(1000); - * ``` - * - * @param milliseconds - the number of milliseconds to wait. - */ - async waitForTimeout(milliseconds: number): Promise { - return await new Promise(resolve => { - setTimeout(resolve, milliseconds); - }); - } - /** * The frame's title. */ diff --git a/packages/puppeteer-core/src/api/Page.ts b/packages/puppeteer-core/src/api/Page.ts index 30882f8e067..70985b93543 100644 --- a/packages/puppeteer-core/src/api/Page.ts +++ b/packages/puppeteer-core/src/api/Page.ts @@ -2784,31 +2784,6 @@ export abstract class Page extends EventEmitter { return this.mainFrame().type(selector, text, options); } - /** - * @deprecated Replace with `new Promise(r => setTimeout(r, milliseconds));`. - * - * Causes your script to wait for the given number of milliseconds. - * - * @remarks - * - * It's generally recommended to not wait for a number of seconds, but instead - * use {@link Frame.waitForSelector}, {@link Frame.waitForXPath} or - * {@link Frame.waitForFunction} to wait for exactly the conditions you want. - * - * @example - * - * Wait for 1 second: - * - * ```ts - * await page.waitForTimeout(1000); - * ``` - * - * @param milliseconds - the number of milliseconds to wait. - */ - waitForTimeout(milliseconds: number): Promise { - return this.mainFrame().waitForTimeout(milliseconds); - } - /** * Wait for the `selector` to appear in page. If at the moment of calling the * method the `selector` already exists, the method will return immediately. If diff --git a/test/src/waittask.spec.ts b/test/src/waittask.spec.ts index 8ff52db16fc..97aefa676e0 100644 --- a/test/src/waittask.spec.ts +++ b/test/src/waittask.spec.ts @@ -336,39 +336,6 @@ describe('waittask specs', function () { }); }); - describe('Page.waitForTimeout', () => { - it('waits for the given timeout before resolving', async () => { - const {page, server} = await getTestState(); - await page.goto(server.EMPTY_PAGE); - const startTime = Date.now(); - await page.waitForTimeout(1000); - const endTime = Date.now(); - /* In a perfect world endTime - startTime would be exactly 1000 but we - * expect some fluctuations and for it to be off by a little bit. So to - * avoid a flaky test we'll make sure it waited for roughly 1 second. - */ - expect(endTime - startTime).toBeGreaterThan(700); - expect(endTime - startTime).toBeLessThan(1300); - }); - }); - - describe('Frame.waitForTimeout', () => { - it('waits for the given timeout before resolving', async () => { - const {page, server} = await getTestState(); - await page.goto(server.EMPTY_PAGE); - const frame = page.mainFrame(); - const startTime = Date.now(); - await frame.waitForTimeout(1000); - const endTime = Date.now(); - /* In a perfect world endTime - startTime would be exactly 1000 but we - * expect some fluctuations and for it to be off by a little bit. So to - * avoid a flaky test we'll make sure it waited for roughly 1 second - */ - expect(endTime - startTime).toBeGreaterThan(700); - expect(endTime - startTime).toBeLessThan(1300); - }); - }); - describe('Frame.waitForSelector', function () { const addElement = (tag: string) => { return document.body.appendChild(document.createElement(tag));