chore: migrate src/DOMWorld to TypeScript (#5764)

This commit is contained in:
Jack Franklin 2020-04-28 15:35:43 +01:00 committed by GitHub
parent d69fbb9974
commit 01578446fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 224 deletions

View File

@ -14,60 +14,50 @@
* limitations under the License. * limitations under the License.
*/ */
const fs = require('fs'); import * as fs from 'fs';
const {helper, assert} = require('./helper'); import {helper, assert} from './helper';
const {LifecycleWatcher} = require('./LifecycleWatcher'); import {LifecycleWatcher, PuppeteerLifeCycleEvent} from './LifecycleWatcher';
const {TimeoutError} = require('./Errors'); import {TimeoutError} from './Errors';
// Used as a TypeDef import {JSHandle, ElementHandle} from './JSHandle';
// eslint-disable-next-line no-unused-vars import {ExecutionContext} from './ExecutionContext';
const {JSHandle, ElementHandle} = require('./JSHandle'); import {TimeoutSettings} from './TimeoutSettings';
// Used as a TypeDef import {MouseButtonInput} from './Input';
// eslint-disable-next-line no-unused-vars
const {ExecutionContext} = require('./ExecutionContext');
// Used as a TypeDef
// eslint-disable-next-line no-unused-vars
const {TimeoutSettings} = require('./TimeoutSettings');
const readFileAsync = helper.promisify(fs.readFile); const readFileAsync = helper.promisify(fs.readFile);
/** interface WaitForSelectorOptions {
* @unrestricted visible?: boolean;
*/ hidden?: boolean;
class DOMWorld { timeout?: number;
/** }
* @param {!Puppeteer.FrameManager} frameManager
* @param {!Puppeteer.Frame} frame export class DOMWorld {
* @param {!TimeoutSettings} timeoutSettings _frameManager: Puppeteer.FrameManager;
*/ _frame: Puppeteer.Frame;
constructor(frameManager, frame, timeoutSettings) { _timeoutSettings: TimeoutSettings;
_documentPromise?: Promise<ElementHandle> = null;
_contextPromise?: Promise<ExecutionContext> = null;
_contextResolveCallback?: (x?: ExecutionContext) => void = null;
_detached = false;
_waitTasks = new Set<WaitTask>();
constructor(frameManager: Puppeteer.FrameManager, frame: Puppeteer.Frame, timeoutSettings: TimeoutSettings) {
this._frameManager = frameManager; this._frameManager = frameManager;
this._frame = frame; this._frame = frame;
this._timeoutSettings = timeoutSettings; this._timeoutSettings = timeoutSettings;
/** @type {?Promise<!ElementHandle>} */
this._documentPromise = null;
/** @type {!Promise<!ExecutionContext>} */
this._contextPromise;
this._contextResolveCallback = null;
this._setContext(null); this._setContext(null);
/** @type {!Set<!WaitTask>} */
this._waitTasks = new Set();
this._detached = false;
} }
/** frame(): Puppeteer.Frame {
* @return {!Puppeteer.Frame}
*/
frame() {
return this._frame; return this._frame;
} }
/** /**
* @param {?ExecutionContext} context * @param {?ExecutionContext} context
*/ */
_setContext(context) { _setContext(context?: ExecutionContext): void {
if (context) { if (context) {
this._contextResolveCallback.call(null, context); this._contextResolveCallback.call(null, context);
this._contextResolveCallback = null; this._contextResolveCallback = null;
@ -81,14 +71,11 @@ class DOMWorld {
} }
} }
/** _hasContext(): boolean {
* @return {boolean}
*/
_hasContext() {
return !this._contextResolveCallback; return !this._contextResolveCallback;
} }
_detach() { _detach(): void {
this._detached = true; this._detached = true;
for (const waitTask of this._waitTasks) for (const waitTask of this._waitTasks)
waitTask.terminate(new Error('waitForFunction failed: frame got detached.')); waitTask.terminate(new Error('waitForFunction failed: frame got detached.'));
@ -97,7 +84,7 @@ class DOMWorld {
/** /**
* @return {!Promise<!ExecutionContext>} * @return {!Promise<!ExecutionContext>}
*/ */
executionContext() { executionContext(): Promise<ExecutionContext> {
if (this._detached) if (this._detached)
throw new Error(`Execution Context is not available in detached frame "${this._frame.url()}" (are you trying to evaluate?)`); throw new Error(`Execution Context is not available in detached frame "${this._frame.url()}" (are you trying to evaluate?)`);
return this._contextPromise; return this._contextPromise;
@ -108,7 +95,7 @@ class DOMWorld {
* @param {!Array<*>} args * @param {!Array<*>} args
* @return {!Promise<!JSHandle>} * @return {!Promise<!JSHandle>}
*/ */
async evaluateHandle(pageFunction, ...args) { async evaluateHandle(pageFunction: Function | string, ...args: unknown[]): Promise<JSHandle> {
const context = await this.executionContext(); const context = await this.executionContext();
return context.evaluateHandle(pageFunction, ...args); return context.evaluateHandle(pageFunction, ...args);
} }
@ -118,25 +105,22 @@ class DOMWorld {
* @param {!Array<*>} args * @param {!Array<*>} args
* @return {!Promise<*>} * @return {!Promise<*>}
*/ */
async evaluate(pageFunction, ...args) { async evaluate<ReturnType extends any>(pageFunction: Function | string, ...args: unknown[]): Promise<ReturnType> {
const context = await this.executionContext(); const context = await this.executionContext();
return context.evaluate(pageFunction, ...args); return context.evaluate<ReturnType>(pageFunction, ...args);
} }
/** /**
* @param {string} selector * @param {string} selector
* @return {!Promise<?ElementHandle>} * @return {!Promise<?ElementHandle>}
*/ */
async $(selector) { async $(selector: string): Promise<ElementHandle | null> {
const document = await this._document(); const document = await this._document();
const value = await document.$(selector); const value = await document.$(selector);
return value; return value;
} }
/** async _document(): Promise<ElementHandle> {
* @return {!Promise<!ElementHandle>}
*/
async _document() {
if (this._documentPromise) if (this._documentPromise)
return this._documentPromise; return this._documentPromise;
this._documentPromise = this.executionContext().then(async context => { this._documentPromise = this.executionContext().then(async context => {
@ -146,36 +130,20 @@ class DOMWorld {
return this._documentPromise; return this._documentPromise;
} }
/** async $x(expression: string): Promise<ElementHandle[]> {
* @param {string} expression
* @return {!Promise<!Array<!ElementHandle>>}
*/
async $x(expression) {
const document = await this._document(); const document = await this._document();
const value = await document.$x(expression); const value = await document.$x(expression);
return value; return value;
} }
/** async $eval<ReturnType extends any>(selector: string, pageFunction: Function | string, ...args: unknown[]): Promise<ReturnType> {
* @param {string} selector
* @param {Function|string} pageFunction
* @param {!Array<*>} args
* @return {!Promise<(!Object|undefined)>}
*/
async $eval(selector, pageFunction, ...args) {
const document = await this._document(); const document = await this._document();
return document.$eval(selector, pageFunction, ...args); return document.$eval<ReturnType>(selector, pageFunction, ...args);
} }
/** async $$eval<ReturnType extends any>(selector: string, pageFunction: Function | string, ...args: unknown[]): Promise<ReturnType> {
* @param {string} selector
* @param {Function|string} pageFunction
* @param {!Array<*>} args
* @return {!Promise<(!Object|undefined)>}
*/
async $$eval(selector, pageFunction, ...args) {
const document = await this._document(); const document = await this._document();
const value = await document.$$eval(selector, pageFunction, ...args); const value = await document.$$eval<ReturnType>(selector, pageFunction, ...args);
return value; return value;
} }
@ -183,16 +151,13 @@ class DOMWorld {
* @param {string} selector * @param {string} selector
* @return {!Promise<!Array<!ElementHandle>>} * @return {!Promise<!Array<!ElementHandle>>}
*/ */
async $$(selector) { async $$(selector: string): Promise<ElementHandle[]> {
const document = await this._document(); const document = await this._document();
const value = await document.$$(selector); const value = await document.$$(selector);
return value; return value;
} }
/** async content(): Promise<string> {
* @return {!Promise<String>}
*/
async content() {
return await this.evaluate(() => { return await this.evaluate(() => {
let retVal = ''; let retVal = '';
if (document.doctype) if (document.doctype)
@ -203,11 +168,7 @@ class DOMWorld {
}); });
} }
/** async setContent(html: string, options: {timeout?: number; waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]} = {}): Promise<void> {
* @param {string} html
* @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array<!Puppeteer.PuppeteerLifeCycleEvent>}=} options
*/
async setContent(html, options = {}) {
const { const {
waitUntil = ['load'], waitUntil = ['load'],
timeout = this._timeoutSettings.navigationTimeout(), timeout = this._timeoutSettings.navigationTimeout(),
@ -233,7 +194,7 @@ class DOMWorld {
* @param {!{url?: string, path?: string, content?: string, type?: string}} options * @param {!{url?: string, path?: string, content?: string, type?: string}} options
* @return {!Promise<!ElementHandle>} * @return {!Promise<!ElementHandle>}
*/ */
async addScriptTag(options) { async addScriptTag(options: {url?: string; path?: string; content?: string; type?: string}): Promise<ElementHandle> {
const { const {
url = null, url = null,
path = null, path = null,
@ -263,12 +224,7 @@ class DOMWorld {
throw new Error('Provide an object with a `url`, `path` or `content` property'); throw new Error('Provide an object with a `url`, `path` or `content` property');
/** async function addScriptUrl(url: string, type: string): Promise<HTMLElement> {
* @param {string} url
* @param {string} type
* @return {!Promise<!HTMLElement>}
*/
async function addScriptUrl(url, type) {
const script = document.createElement('script'); const script = document.createElement('script');
script.src = url; script.src = url;
if (type) if (type)
@ -282,12 +238,7 @@ class DOMWorld {
return script; return script;
} }
/** function addScriptContent(content: string, type = 'text/javascript'): HTMLElement {
* @param {string} content
* @param {string} type
* @return {!HTMLElement}
*/
function addScriptContent(content, type = 'text/javascript') {
const script = document.createElement('script'); const script = document.createElement('script');
script.type = type; script.type = type;
script.text = content; script.text = content;
@ -300,11 +251,7 @@ class DOMWorld {
} }
} }
/** async addStyleTag(options: {url?: string; path?: string; content?: string}): Promise<ElementHandle> {
* @param {!{url?: string, path?: string, content?: string}} options
* @return {!Promise<!ElementHandle>}
*/
async addStyleTag(options) {
const { const {
url = null, url = null,
path = null, path = null,
@ -333,11 +280,7 @@ class DOMWorld {
throw new Error('Provide an object with a `url`, `path` or `content` property'); throw new Error('Provide an object with a `url`, `path` or `content` property');
/** async function addStyleUrl(url: string): Promise<HTMLElement> {
* @param {string} url
* @return {!Promise<!HTMLElement>}
*/
async function addStyleUrl(url) {
const link = document.createElement('link'); const link = document.createElement('link');
link.rel = 'stylesheet'; link.rel = 'stylesheet';
link.href = url; link.href = url;
@ -350,11 +293,7 @@ class DOMWorld {
return link; return link;
} }
/** async function addStyleContent(content: string): Promise<HTMLElement> {
* @param {string} content
* @return {!Promise<!HTMLElement>}
*/
async function addStyleContent(content) {
const style = document.createElement('style'); const style = document.createElement('style');
style.type = 'text/css'; style.type = 'text/css';
style.appendChild(document.createTextNode(content)); style.appendChild(document.createTextNode(content));
@ -368,43 +307,28 @@ class DOMWorld {
} }
} }
/** async click(selector: string, options: {delay?: number; button?: MouseButtonInput; clickCount?: number}): Promise<void> {
* @param {string} selector
* @param {!{delay?: number, button?: "left"|"right"|"middle", clickCount?: number}=} options
*/
async click(selector, options) {
const handle = await this.$(selector); const handle = await this.$(selector);
assert(handle, 'No node found for selector: ' + selector); assert(handle, 'No node found for selector: ' + selector);
await handle.click(options); await handle.click(options);
await handle.dispose(); await handle.dispose();
} }
/** async focus(selector: string): Promise<void> {
* @param {string} selector
*/
async focus(selector) {
const handle = await this.$(selector); const handle = await this.$(selector);
assert(handle, 'No node found for selector: ' + selector); assert(handle, 'No node found for selector: ' + selector);
await handle.focus(); await handle.focus();
await handle.dispose(); await handle.dispose();
} }
/** async hover(selector: string): Promise<void> {
* @param {string} selector
*/
async hover(selector) {
const handle = await this.$(selector); const handle = await this.$(selector);
assert(handle, 'No node found for selector: ' + selector); assert(handle, 'No node found for selector: ' + selector);
await handle.hover(); await handle.hover();
await handle.dispose(); await handle.dispose();
} }
/** async select(selector: string, ...values: string[]): Promise<string[]> {
* @param {string} selector
* @param {!Array<string>} values
* @return {!Promise<!Array<string>>}
*/
async select(selector, ...values) {
const handle = await this.$(selector); const handle = await this.$(selector);
assert(handle, 'No node found for selector: ' + selector); assert(handle, 'No node found for selector: ' + selector);
const result = await handle.select(...values); const result = await handle.select(...values);
@ -412,52 +336,29 @@ class DOMWorld {
return result; return result;
} }
/** async tap(selector: string): Promise<void> {
* @param {string} selector
*/
async tap(selector) {
const handle = await this.$(selector); const handle = await this.$(selector);
assert(handle, 'No node found for selector: ' + selector); assert(handle, 'No node found for selector: ' + selector);
await handle.tap(); await handle.tap();
await handle.dispose(); await handle.dispose();
} }
/** async type(selector: string, text: string, options?: {delay: number}): Promise<void> {
* @param {string} selector
* @param {string} text
* @param {{delay: (number|undefined)}=} options
*/
async type(selector, text, options) {
const handle = await this.$(selector); const handle = await this.$(selector);
assert(handle, 'No node found for selector: ' + selector); assert(handle, 'No node found for selector: ' + selector);
await handle.type(text, options); await handle.type(text, options);
await handle.dispose(); await handle.dispose();
} }
/** waitForSelector(selector: string, options: WaitForSelectorOptions): Promise<ElementHandle | null> {
* @param {string} selector
* @param {!{visible?: boolean, hidden?: boolean, timeout?: number}=} options
* @return {!Promise<?ElementHandle>}
*/
waitForSelector(selector, options) {
return this._waitForSelectorOrXPath(selector, false, options); return this._waitForSelectorOrXPath(selector, false, options);
} }
/** waitForXPath(xpath: string, options: WaitForSelectorOptions): Promise<ElementHandle | null> {
* @param {string} xpath
* @param {!{visible?: boolean, hidden?: boolean, timeout?: number}=} options
* @return {!Promise<?ElementHandle>}
*/
waitForXPath(xpath, options) {
return this._waitForSelectorOrXPath(xpath, true, options); return this._waitForSelectorOrXPath(xpath, true, options);
} }
/** waitForFunction(pageFunction: Function | string, options: {polling?: string | number; timeout?: number} = {}, ...args: unknown[]): Promise<JSHandle> {
* @param {Function|string} pageFunction
* @param {!{polling?: string|number, timeout?: number}=} options
* @return {!Promise<!JSHandle>}
*/
waitForFunction(pageFunction, options = {}, ...args) {
const { const {
polling = 'raf', polling = 'raf',
timeout = this._timeoutSettings.timeout(), timeout = this._timeoutSettings.timeout(),
@ -465,20 +366,11 @@ class DOMWorld {
return new WaitTask(this, pageFunction, 'function', polling, timeout, ...args).promise; return new WaitTask(this, pageFunction, 'function', polling, timeout, ...args).promise;
} }
/** async title(): Promise<string> {
* @return {!Promise<string>}
*/
async title() {
return this.evaluate(() => document.title); return this.evaluate(() => document.title);
} }
/** private async _waitForSelectorOrXPath(selectorOrXPath: string, isXPath: boolean, options: WaitForSelectorOptions = {}): Promise<ElementHandle | null> {
* @param {string} selectorOrXPath
* @param {boolean} isXPath
* @param {!{visible?: boolean, hidden?: boolean, timeout?: number}=} options
* @return {!Promise<?ElementHandle>}
*/
async _waitForSelectorOrXPath(selectorOrXPath, isXPath, options = {}) {
const { const {
visible: waitForVisible = false, visible: waitForVisible = false,
hidden: waitForHidden = false, hidden: waitForHidden = false,
@ -501,7 +393,7 @@ class DOMWorld {
* @param {boolean} waitForHidden * @param {boolean} waitForHidden
* @return {?Node|boolean} * @return {?Node|boolean}
*/ */
function predicate(selectorOrXPath, isXPath, waitForVisible, waitForHidden) { function predicate(selectorOrXPath: string, isXPath: boolean, waitForVisible: boolean, waitForHidden: boolean): Node | null | boolean {
const node = isXPath const node = isXPath
? document.evaluate(selectorOrXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ? document.evaluate(selectorOrXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
: document.querySelector(selectorOrXPath); : document.querySelector(selectorOrXPath);
@ -509,17 +401,14 @@ class DOMWorld {
return waitForHidden; return waitForHidden;
if (!waitForVisible && !waitForHidden) if (!waitForVisible && !waitForHidden)
return node; return node;
const element = /** @type {Element} */ (node.nodeType === Node.TEXT_NODE ? node.parentElement : node); const element = (node.nodeType === Node.TEXT_NODE ? node.parentElement : node as Element);
const style = window.getComputedStyle(element); const style = window.getComputedStyle(element);
const isVisible = style && style.visibility !== 'hidden' && hasVisibleBoundingBox(); const isVisible = style && style.visibility !== 'hidden' && hasVisibleBoundingBox();
const success = (waitForVisible === isVisible || waitForHidden === !isVisible); const success = (waitForVisible === isVisible || waitForHidden === !isVisible);
return success ? node : null; return success ? node : null;
/** function hasVisibleBoundingBox(): boolean {
* @return {boolean}
*/
function hasVisibleBoundingBox() {
const rect = element.getBoundingClientRect(); const rect = element.getBoundingClientRect();
return !!(rect.top || rect.bottom || rect.width || rect.height); return !!(rect.top || rect.bottom || rect.width || rect.height);
} }
@ -528,14 +417,19 @@ class DOMWorld {
} }
class WaitTask { class WaitTask {
/** _domWorld: DOMWorld;
* @param {!DOMWorld} domWorld _polling: string | number;
* @param {Function|string} predicateBody _timeout: number;
* @param {string|number} polling _predicateBody: string;
* @param {number} timeout _args: unknown[];
* @param {!Array<*>} args _runCount = 0;
*/ promise: Promise<JSHandle>;
constructor(domWorld, predicateBody, title, polling, timeout, ...args) { _resolve: (x: JSHandle) => void;
_reject: (x: Error) => void;
_timeoutTimer?: NodeJS.Timeout;
_terminated = false;
constructor(domWorld: DOMWorld, predicateBody: Function | string, title: string, polling: string | number, timeout: number, ...args: unknown[]) {
if (helper.isString(polling)) if (helper.isString(polling))
assert(polling === 'raf' || polling === 'mutation', 'Unknown polling option: ' + polling); assert(polling === 'raf' || polling === 'mutation', 'Unknown polling option: ' + polling);
else if (helper.isNumber(polling)) else if (helper.isNumber(polling))
@ -550,7 +444,7 @@ class WaitTask {
this._args = args; this._args = args;
this._runCount = 0; this._runCount = 0;
domWorld._waitTasks.add(this); domWorld._waitTasks.add(this);
this.promise = new Promise((resolve, reject) => { this.promise = new Promise<JSHandle>((resolve, reject) => {
this._resolve = resolve; this._resolve = resolve;
this._reject = reject; this._reject = reject;
}); });
@ -563,16 +457,13 @@ class WaitTask {
this.rerun(); this.rerun();
} }
/** terminate(error: Error): void {
* @param {!Error} error
*/
terminate(error) {
this._terminated = true; this._terminated = true;
this._reject(error); this._reject(error);
this._cleanup(); this._cleanup();
} }
async rerun() { async rerun(): Promise<void> {
const runCount = ++this._runCount; const runCount = ++this._runCount;
/** @type {?JSHandle} */ /** @type {?JSHandle} */
let success = null; let success = null;
@ -592,7 +483,7 @@ class WaitTask {
// Ignore timeouts in pageScript - we track timeouts ourselves. // Ignore timeouts in pageScript - we track timeouts ourselves.
// If the frame's execution context has already changed, `frame.evaluate` will // If the frame's execution context has already changed, `frame.evaluate` will
// throw an error - ignore this predicate run altogether. // throw an error - ignore this predicate run altogether.
if (!error && await this._domWorld.evaluate(s => !s, success).catch(error_ => true)) { if (!error && await this._domWorld.evaluate(s => !s, success).catch(() => true)) {
await success.dispose(); await success.dispose();
return; return;
} }
@ -615,20 +506,13 @@ class WaitTask {
this._cleanup(); this._cleanup();
} }
_cleanup() { _cleanup(): void {
clearTimeout(this._timeoutTimer); clearTimeout(this._timeoutTimer);
this._domWorld._waitTasks.delete(this); this._domWorld._waitTasks.delete(this);
this._runningTask = null;
} }
} }
/** async function waitForPredicatePageFunction(predicateBody: string, polling: string, timeout: number, ...args: unknown[]): Promise<unknown> {
* @param {string} predicateBody
* @param {string} polling
* @param {number} timeout
* @return {!Promise<*>}
*/
async function waitForPredicatePageFunction(predicateBody, polling, timeout, ...args) {
const predicate = new Function('...args', predicateBody); const predicate = new Function('...args', predicateBody);
let timedOut = false; let timedOut = false;
if (timeout) if (timeout)
@ -643,19 +527,19 @@ async function waitForPredicatePageFunction(predicateBody, polling, timeout, ...
/** /**
* @return {!Promise<*>} * @return {!Promise<*>}
*/ */
function pollMutation() { function pollMutation(): Promise<unknown> {
const success = predicate.apply(null, args); const success = predicate(...args);
if (success) if (success)
return Promise.resolve(success); return Promise.resolve(success);
let fulfill; let fulfill;
const result = new Promise(x => fulfill = x); const result = new Promise(x => fulfill = x);
const observer = new MutationObserver(mutations => { const observer = new MutationObserver(() => {
if (timedOut) { if (timedOut) {
observer.disconnect(); observer.disconnect();
fulfill(); fulfill();
} }
const success = predicate.apply(null, args); const success = predicate(...args);
if (success) { if (success) {
observer.disconnect(); observer.disconnect();
fulfill(success); fulfill(success);
@ -669,21 +553,18 @@ async function waitForPredicatePageFunction(predicateBody, polling, timeout, ...
return result; return result;
} }
/** function pollRaf(): Promise<unknown> {
* @return {!Promise<*>}
*/
function pollRaf() {
let fulfill; let fulfill;
const result = new Promise(x => fulfill = x); const result = new Promise(x => fulfill = x);
onRaf(); onRaf();
return result; return result;
function onRaf() { function onRaf(): void {
if (timedOut) { if (timedOut) {
fulfill(); fulfill();
return; return;
} }
const success = predicate.apply(null, args); const success = predicate(...args);
if (success) if (success)
fulfill(success); fulfill(success);
else else
@ -691,22 +572,18 @@ async function waitForPredicatePageFunction(predicateBody, polling, timeout, ...
} }
} }
/** function pollInterval(pollInterval: number): Promise<unknown> {
* @param {number} pollInterval
* @return {!Promise<*>}
*/
function pollInterval(pollInterval) {
let fulfill; let fulfill;
const result = new Promise(x => fulfill = x); const result = new Promise(x => fulfill = x);
onTimeout(); onTimeout();
return result; return result;
function onTimeout() { function onTimeout(): void {
if (timedOut) { if (timedOut) {
fulfill(); fulfill();
return; return;
} }
const success = predicate.apply(null, args); const success = predicate(...args);
if (success) if (success)
fulfill(success); fulfill(success);
else else
@ -714,5 +591,3 @@ async function waitForPredicatePageFunction(predicateBody, polling, timeout, ...
} }
} }
} }
module.exports = {DOMWorld};

View File

@ -153,7 +153,7 @@ export class Keyboard {
} }
type MouseButton = 'none' | 'left' | 'right' | 'middle'; type MouseButton = 'none' | 'left' | 'right' | 'middle';
type MouseButtonInput = Exclude<MouseButton, 'none'>; export type MouseButtonInput = Exclude<MouseButton, 'none'>;
interface MouseOptions { interface MouseOptions {
button?: MouseButtonInput; button?: MouseButtonInput;

View File

@ -18,7 +18,7 @@ import {helper, assert, PuppeteerEventListener} from './helper';
import {Events} from './Events'; import {Events} from './Events';
import {TimeoutError} from './Errors'; import {TimeoutError} from './Errors';
type PuppeteerLifeCycleEvent = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'; export type PuppeteerLifeCycleEvent = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';
type ProtocolLifeCycleEvent = 'load' | 'DOMContentLoaded' | 'networkIdle' | 'networkAlmostIdle'; type ProtocolLifeCycleEvent = 'load' | 'DOMContentLoaded' | 'networkIdle' | 'networkAlmostIdle';
const puppeteerToProtocolLifecycle = new Map<PuppeteerLifeCycleEvent, ProtocolLifeCycleEvent>([ const puppeteerToProtocolLifecycle = new Map<PuppeteerLifeCycleEvent, ProtocolLifeCycleEvent>([

View File

@ -16,7 +16,7 @@
const DEFAULT_TIMEOUT = 30000; const DEFAULT_TIMEOUT = 30000;
class TimeoutSettings { export class TimeoutSettings {
_defaultTimeout: number | null; _defaultTimeout: number | null;
_defaultNavigationTimeout: number | null; _defaultNavigationTimeout: number | null;
@ -50,5 +50,3 @@ class TimeoutSettings {
return DEFAULT_TIMEOUT; return DEFAULT_TIMEOUT;
} }
} }
export = {TimeoutSettings};