mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: migrate src/LifecycleWatcher (#5734)
This commit is contained in:
parent
79e82e5b65
commit
1358b45fca
18
docs/api.md
18
docs/api.md
@ -1554,7 +1554,7 @@ Shortcut for [page.mainFrame().focus(selector)](#framefocusselector).
|
||||
#### page.goBack([options])
|
||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleMethod>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `load` - consider navigation to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
||||
@ -1567,7 +1567,7 @@ Navigate to the previous page in history.
|
||||
#### page.goForward([options])
|
||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleMethod>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `load` - consider navigation to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
||||
@ -1581,7 +1581,7 @@ Navigate to the next page in history.
|
||||
- `url` <[string]> URL to navigate page to. The url should include scheme, e.g. `https://`.
|
||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleMethod>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `load` - consider navigation to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
||||
@ -1742,7 +1742,7 @@ Shortcut for [page.mainFrame().executionContext().queryObjects(prototypeHandle)]
|
||||
#### page.reload([options])
|
||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleMethod>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `load` - consider navigation to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
||||
@ -1800,7 +1800,7 @@ Toggles ignoring cache for each request based on the enabled state. By default,
|
||||
- `html` <[string]> HTML markup to assign to the page.
|
||||
- `options` <[Object]> Parameters which might have the following properties:
|
||||
- `timeout` <[number]> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- `waitUntil` <[string]|[Array]<[string]>> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either:
|
||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleMethod>> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either:
|
||||
- `load` - consider setting content to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider setting content to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider setting content to be finished when there are no more than 0 network connections for at least `500` ms.
|
||||
@ -2101,7 +2101,7 @@ Shortcut for [page.mainFrame().waitForFunction(pageFunction[, options[, ...args]
|
||||
#### page.waitForNavigation([options])
|
||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleMethod>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `load` - consider navigation to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
||||
@ -2804,7 +2804,7 @@ If there's no element matching `selector`, the method throws an error.
|
||||
- `url` <[string]> URL to navigate frame to. The url should include scheme, e.g. `https://`.
|
||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleMethod>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `load` - consider navigation to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
||||
@ -2867,7 +2867,7 @@ frame.select('select#colors', 'red', 'green', 'blue'); // multiple selections
|
||||
- `html` <[string]> HTML markup to assign to the page.
|
||||
- `options` <[Object]> Parameters which might have the following properties:
|
||||
- `timeout` <[number]> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- `waitUntil` <[string]|[Array]<[string]>> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either:
|
||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleMethod>> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either:
|
||||
- `load` - consider setting content to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider setting content to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider setting content to be finished when there are no more than 0 network connections for at least `500` ms.
|
||||
@ -2968,7 +2968,7 @@ await page.waitForFunction(selector => !!document.querySelector(selector), {}, s
|
||||
#### frame.waitForNavigation([options])
|
||||
- `options` <[Object]> Navigation parameters which might have the following properties:
|
||||
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
|
||||
- `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleMethod>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
||||
- `load` - consider navigation to be finished when the `load` event is fired.
|
||||
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||
- `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
||||
|
@ -205,7 +205,7 @@ class DOMWorld {
|
||||
|
||||
/**
|
||||
* @param {string} html
|
||||
* @param {!{timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
*/
|
||||
async setContent(html, options = {}) {
|
||||
const {
|
||||
|
@ -89,7 +89,7 @@ class FrameManager extends EventEmitter {
|
||||
/**
|
||||
* @param {!Puppeteer.Frame} frame
|
||||
* @param {string} url
|
||||
* @param {!{referer?: string, timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{referer?: string, timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
* @return {!Promise<?Puppeteer.Response>}
|
||||
*/
|
||||
async navigateFrame(frame, url, options = {}) {
|
||||
@ -137,7 +137,7 @@ class FrameManager extends EventEmitter {
|
||||
|
||||
/**
|
||||
* @param {!Puppeteer.Frame} frame
|
||||
* @param {!{timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
* @return {!Promise<?Puppeteer.Response>}
|
||||
*/
|
||||
async waitForFrameNavigation(frame, options = {}) {
|
||||
@ -410,7 +410,7 @@ class Frame {
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {!{referer?: string, timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{referer?: string, timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
* @return {!Promise<?Puppeteer.Response>}
|
||||
*/
|
||||
async goto(url, options) {
|
||||
@ -418,7 +418,7 @@ class Frame {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!{timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
* @return {!Promise<?Puppeteer.Response>}
|
||||
*/
|
||||
async waitForNavigation(options) {
|
||||
@ -503,7 +503,7 @@ class Frame {
|
||||
|
||||
/**
|
||||
* @param {string} html
|
||||
* @param {!{timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
*/
|
||||
async setContent(html, options = {}) {
|
||||
return this._secondaryWorld.setContent(html, options);
|
||||
|
@ -14,18 +14,49 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const {helper, assert} = require('./helper');
|
||||
const {Events} = require('./Events');
|
||||
const {TimeoutError} = require('./Errors');
|
||||
import {helper, assert, PuppeteerEventListener} from './helper';
|
||||
import {Events} from './Events';
|
||||
import {TimeoutError} from './Errors';
|
||||
|
||||
class LifecycleWatcher {
|
||||
/**
|
||||
* @param {!Puppeteer.FrameManager} frameManager
|
||||
* @param {!Puppeteer.Frame} frame
|
||||
* @param {string|!Array<string>} waitUntil
|
||||
* @param {number} timeout
|
||||
*/
|
||||
constructor(frameManager, frame, waitUntil, timeout) {
|
||||
type PuppeteerLifeCycleEvent = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';
|
||||
type ProtocolLifeCycleEvent = 'load' | 'DOMContentLoaded' | 'networkIdle' | 'networkAlmostIdle';
|
||||
|
||||
const puppeteerToProtocolLifecycle = new Map<PuppeteerLifeCycleEvent, ProtocolLifeCycleEvent>([
|
||||
['load', 'load'],
|
||||
['domcontentloaded', 'DOMContentLoaded'],
|
||||
['networkidle0', 'networkIdle'],
|
||||
['networkidle2', 'networkAlmostIdle'],
|
||||
]);
|
||||
|
||||
|
||||
export class LifecycleWatcher {
|
||||
_expectedLifecycle: ProtocolLifeCycleEvent[];
|
||||
_frameManager: Puppeteer.FrameManager;
|
||||
_frame: Puppeteer.Frame;
|
||||
_timeout: number;
|
||||
_navigationRequest?: Puppeteer.Request;
|
||||
_eventListeners: PuppeteerEventListener[];
|
||||
_initialLoaderId: string;
|
||||
|
||||
|
||||
_sameDocumentNavigationPromise: Promise<Error | null>;
|
||||
_sameDocumentNavigationCompleteCallback: (x?: Error) => void;
|
||||
|
||||
_lifecyclePromise: Promise<void>;
|
||||
_lifecycleCallback: () => void;
|
||||
|
||||
_newDocumentNavigationPromise: Promise<Error | null>;
|
||||
_newDocumentNavigationCompleteCallback: (x?: Error) => void;
|
||||
|
||||
_terminationPromise: Promise<Error | null>;
|
||||
_terminationCallback: (x?: Error) => void;
|
||||
|
||||
_timeoutPromise: Promise<TimeoutError | null>;
|
||||
|
||||
_maximumTimer?: NodeJS.Timeout;
|
||||
_hasSameDocumentNavigation?: boolean;
|
||||
|
||||
constructor(frameManager: Puppeteer.FrameManager, frame: Puppeteer.Frame, waitUntil: PuppeteerLifeCycleEvent|PuppeteerLifeCycleEvent[], timeout: number) {
|
||||
if (Array.isArray(waitUntil))
|
||||
waitUntil = waitUntil.slice();
|
||||
else if (typeof waitUntil === 'string')
|
||||
@ -50,7 +81,7 @@ class LifecycleWatcher {
|
||||
helper.addEventListener(this._frameManager.networkManager(), Events.NetworkManager.Request, this._onRequest.bind(this)),
|
||||
];
|
||||
|
||||
this._sameDocumentNavigationPromise = new Promise(fulfill => {
|
||||
this._sameDocumentNavigationPromise = new Promise<Error | null>(fulfill => {
|
||||
this._sameDocumentNavigationCompleteCallback = fulfill;
|
||||
});
|
||||
|
||||
@ -69,19 +100,13 @@ class LifecycleWatcher {
|
||||
this._checkLifecycleComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Puppeteer.Request} request
|
||||
*/
|
||||
_onRequest(request) {
|
||||
_onRequest(request: Puppeteer.Request): void {
|
||||
if (request.frame() !== this._frame || !request.isNavigationRequest())
|
||||
return;
|
||||
this._navigationRequest = request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Puppeteer.Frame} frame
|
||||
*/
|
||||
_onFrameDetached(frame) {
|
||||
_onFrameDetached(frame: Puppeteer.Frame): void {
|
||||
if (this._frame === frame) {
|
||||
this._terminationCallback.call(null, new Error('Navigating frame was detached'));
|
||||
return;
|
||||
@ -89,52 +114,31 @@ class LifecycleWatcher {
|
||||
this._checkLifecycleComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {?Puppeteer.Response}
|
||||
*/
|
||||
navigationResponse() {
|
||||
navigationResponse(): Puppeteer.Response | null {
|
||||
return this._navigationRequest ? this._navigationRequest.response() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Error} error
|
||||
*/
|
||||
_terminate(error) {
|
||||
_terminate(error: Error): void {
|
||||
this._terminationCallback.call(null, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Promise<?Error>}
|
||||
*/
|
||||
sameDocumentNavigationPromise() {
|
||||
sameDocumentNavigationPromise(): Promise<Error | null> {
|
||||
return this._sameDocumentNavigationPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Promise<?Error>}
|
||||
*/
|
||||
newDocumentNavigationPromise() {
|
||||
newDocumentNavigationPromise(): Promise<Error | null> {
|
||||
return this._newDocumentNavigationPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Promise}
|
||||
*/
|
||||
lifecyclePromise() {
|
||||
lifecyclePromise(): Promise<void> {
|
||||
return this._lifecyclePromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Promise<?Error>}
|
||||
*/
|
||||
timeoutOrTerminationPromise() {
|
||||
timeoutOrTerminationPromise(): Promise<Error | TimeoutError | null> {
|
||||
return Promise.race([this._timeoutPromise, this._terminationPromise]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Promise<?Error>}
|
||||
*/
|
||||
_createTimeoutPromise() {
|
||||
_createTimeoutPromise(): Promise<TimeoutError | null> {
|
||||
if (!this._timeout)
|
||||
return new Promise(() => {});
|
||||
const errorMessage = 'Navigation timeout of ' + this._timeout + ' ms exceeded';
|
||||
@ -142,17 +146,14 @@ class LifecycleWatcher {
|
||||
.then(() => new TimeoutError(errorMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Puppeteer.Frame} frame
|
||||
*/
|
||||
_navigatedWithinDocument(frame) {
|
||||
_navigatedWithinDocument(frame: Puppeteer.Frame): void {
|
||||
if (frame !== this._frame)
|
||||
return;
|
||||
this._hasSameDocumentNavigation = true;
|
||||
this._checkLifecycleComplete();
|
||||
}
|
||||
|
||||
_checkLifecycleComplete() {
|
||||
_checkLifecycleComplete(): void {
|
||||
// We expect navigation to commit.
|
||||
if (!checkLifecycle(this._frame, this._expectedLifecycle))
|
||||
return;
|
||||
@ -169,7 +170,7 @@ class LifecycleWatcher {
|
||||
* @param {!Array<string>} expectedLifecycle
|
||||
* @return {boolean}
|
||||
*/
|
||||
function checkLifecycle(frame, expectedLifecycle) {
|
||||
function checkLifecycle(frame: Puppeteer.Frame, expectedLifecycle: ProtocolLifeCycleEvent[]): boolean {
|
||||
for (const event of expectedLifecycle) {
|
||||
if (!frame._lifecycleEvents.has(event))
|
||||
return false;
|
||||
@ -182,17 +183,8 @@ class LifecycleWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
dispose(): void {
|
||||
helper.removeEventListeners(this._eventListeners);
|
||||
clearTimeout(this._maximumTimer);
|
||||
}
|
||||
}
|
||||
|
||||
const puppeteerToProtocolLifecycle = new Map([
|
||||
['load', 'load'],
|
||||
['domcontentloaded', 'DOMContentLoaded'],
|
||||
['networkidle0', 'networkIdle'],
|
||||
['networkidle2', 'networkAlmostIdle'],
|
||||
]);
|
||||
|
||||
module.exports = {LifecycleWatcher};
|
14
src/Page.js
14
src/Page.js
@ -675,7 +675,7 @@ class Page extends EventEmitter {
|
||||
|
||||
/**
|
||||
* @param {string} html
|
||||
* @param {!{timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
*/
|
||||
async setContent(html, options) {
|
||||
await this._frameManager.mainFrame().setContent(html, options);
|
||||
@ -683,7 +683,7 @@ class Page extends EventEmitter {
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {!{referer?: string, timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{referer?: string, timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
* @return {!Promise<?Puppeteer.Response>}
|
||||
*/
|
||||
async goto(url, options) {
|
||||
@ -691,7 +691,7 @@ class Page extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!{timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
* @return {!Promise<?Puppeteer.Response>}
|
||||
*/
|
||||
async reload(options) {
|
||||
@ -705,7 +705,7 @@ class Page extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!{timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
* @return {!Promise<?Puppeteer.Response>}
|
||||
*/
|
||||
async waitForNavigation(options = {}) {
|
||||
@ -755,7 +755,7 @@ class Page extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!{timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
* @return {!Promise<?Puppeteer.Response>}
|
||||
*/
|
||||
async goBack(options) {
|
||||
@ -763,7 +763,7 @@ class Page extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!{timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
* @return {!Promise<?Puppeteer.Response>}
|
||||
*/
|
||||
async goForward(options) {
|
||||
@ -771,7 +771,7 @@ class Page extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!{timeout?: number, waitUntil?: string|!Array<string>}=} options
|
||||
* @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
|
||||
* @return {!Promise<?Puppeteer.Response>}
|
||||
*/
|
||||
async _go(delta, options) {
|
||||
|
6
src/externs.d.ts
vendored
6
src/externs.d.ts
vendored
@ -18,6 +18,12 @@ declare global {
|
||||
export class Response extends RealResponse { }
|
||||
export class Request extends RealRequest { }
|
||||
|
||||
|
||||
/* TODO(jacktfranklin@): once DOMWorld, Page, and FrameManager are in TS
|
||||
* we can remove this and instead use the type defined in LifeCycleWatcher
|
||||
*/
|
||||
export type PuppeteerLifeCycleEvent = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';
|
||||
|
||||
export interface ConnectionTransport {
|
||||
send(string);
|
||||
close();
|
||||
|
@ -299,6 +299,42 @@ function compareDocumentations(actual, expected) {
|
||||
actualName: 'Object',
|
||||
expectedName: 'TracingOptions'
|
||||
}],
|
||||
['Method Frame.goto() options.waitUntil', {
|
||||
actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array',
|
||||
expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleEvent>'
|
||||
}],
|
||||
['Method Frame.waitForNavigation() options.waitUntil', {
|
||||
actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array',
|
||||
expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleEvent>'
|
||||
}],
|
||||
['Method Frame.setContent() options.waitUntil', {
|
||||
actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array',
|
||||
expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleEvent>'
|
||||
}],
|
||||
['Method Page.goBack() options.waitUntil', {
|
||||
actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array',
|
||||
expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleEvent>'
|
||||
}],
|
||||
['Method Page.goForward() options.waitUntil', {
|
||||
actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array',
|
||||
expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleEvent>'
|
||||
}],
|
||||
['Method Page.goto() options.waitUntil', {
|
||||
actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array',
|
||||
expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleEvent>'
|
||||
}],
|
||||
['Method Page.reload() options.waitUntil', {
|
||||
actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array',
|
||||
expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleEvent>'
|
||||
}],
|
||||
['Method Page.setContent() options.waitUntil', {
|
||||
actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array',
|
||||
expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleEvent>'
|
||||
}],
|
||||
['Method Page.waitForNavigation() options.waitUntil', {
|
||||
actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array',
|
||||
expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleEvent>'
|
||||
}],
|
||||
]);
|
||||
|
||||
const expectedForSource = expectedNamingMismatches.get(source);
|
||||
|
@ -80,8 +80,25 @@ function classToString(classDesc) {
|
||||
* @param {import('./check_public_api/Documentation').Type} type
|
||||
*/
|
||||
function typeToString(type, ...namespace) {
|
||||
|
||||
/* A hack to special case TypeScript types that this type generator
|
||||
* does not understand / parse correctly.
|
||||
* Because the goal is to generate these types from the TypeScript
|
||||
* source, this parser won't be around for much longer so investing in
|
||||
* improving the parser's ability is not worth it.
|
||||
*/
|
||||
const specialCaseTypeMaps = new Map([
|
||||
['"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array',
|
||||
'"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<string>']
|
||||
]);
|
||||
|
||||
|
||||
if (!type)
|
||||
return 'void';
|
||||
|
||||
if (specialCaseTypeMaps.has(type.name))
|
||||
return specialCaseTypeMaps.get(type.name);
|
||||
|
||||
let typeString = stringifyType(parseType(type.name));
|
||||
for (let i = 0; i < type.properties.length; i++)
|
||||
typeString = typeString.replace('arg' + i, type.properties[i].name);
|
||||
|
Loading…
Reference in New Issue
Block a user