Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const EventEmitter = require('events');

class Browser extends EventEmitter {
/**
* @param {!Connection} connection
* @param {!Puppeteer.Connection} connection
* @param {!Object=} options
* @param {function():Promise=} closeCallback
* @param {(function():Promise)=} closeCallback
*/
constructor(connection, options = {}, closeCallback) {
super();
Expand Down Expand Up @@ -63,7 +63,6 @@ class Browser extends EventEmitter {
}
}

module.exports = Browser;
helper.tracePublicAPI(Browser);

class TaskQueue {
Expand All @@ -81,3 +80,4 @@ class TaskQueue {
return result;
}
}
module.exports = { Browser, TaskQueue };
4 changes: 2 additions & 2 deletions lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class Session extends EventEmitter {
if (!this._callbacks.has(id))
return;
const callback = this._callbacks.get(id);
this._callbacks.delete(object.id);
this._callbacks.delete(id);
callback.reject(e);
});
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -212,4 +212,4 @@ class Session extends EventEmitter {
}
}

module.exports = Connection;
module.exports = {Connection, Session};
4 changes: 2 additions & 2 deletions lib/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const {helper} = require('./helper');

class Dialog {
/**
* @param {!Session} client
* @param {!Dialog.Type} type
* @param {!Puppeteer.Session} client
* @param {string} type
* @param {string} message
* @param {(string|undefined)} defaultValue
*/
Expand Down
8 changes: 4 additions & 4 deletions lib/ElementHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const {helper} = require('./helper');

class ElementHandle extends JSHandle {
/**
* @param {!ExecutionContext} context
* @param {!Session} client
* @param {!Puppeteer.ExecutionContext} context
* @param {!Puppeteer.Session} client
* @param {!Object} remoteObject
* @param {!Page} page
* @param {!Puppeteer.Page} page
*/
constructor(context, client, remoteObject, page) {
super(context, client, remoteObject);
Expand All @@ -47,7 +47,7 @@ class ElementHandle extends JSHandle {
const error = await this.executionContext().evaluate(element => {
if (!element.ownerDocument.contains(element))
return 'Node is detached from document';
if (element.nodeType !== HTMLElement.ELEMENT_NODE)
if (element.nodeType !== Node.ELEMENT_NODE)
return 'Node is not of type HTMLElement';
element.scrollIntoViewIfNeeded();
}, this);
Expand Down
15 changes: 13 additions & 2 deletions lib/EmulationManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class EmulationManager {
/**
* @param {!Session} client
* @param {!Puppeteer.Session} client
*/
constructor(client) {
this._client = client;
Expand All @@ -25,7 +25,7 @@ class EmulationManager {
}

/**
* @param {!Page.Viewport} viewport
* @param {!EmulationManager.Viewport} viewport
* @return {Promise<boolean>}
*/
async emulateViewport(client, viewport) {
Expand Down Expand Up @@ -61,6 +61,7 @@ class EmulationManager {

function injectedTouchEventsFunction() {
const touchEvents = ['ontouchstart', 'ontouchend', 'ontouchmove', 'ontouchcancel'];
// @ts-ignore
const recepients = [window.__proto__, document.__proto__];
for (let i = 0; i < touchEvents.length; ++i) {
for (let j = 0; j < recepients.length; ++j) {
Expand All @@ -75,4 +76,14 @@ class EmulationManager {
}
}

/**
* @typedef {Object} EmulationManager.Viewport
* @property {number} width
* @property {number} height
* @property {number=} deviceScaleFactor
* @property {boolean=} isMobile
* @property {boolean=} isLandscape
* @property {boolean=} hasTouch
*/

module.exports = EmulationManager;
8 changes: 4 additions & 4 deletions lib/ExecutionContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {helper} = require('./helper');

class ExecutionContext {
/**
* @param {!Session} client
* @param {!Puppeteer.Session} client
* @param {string} contextId
* @param {function(*):!JSHandle} objectHandleFactory
*/
Expand Down Expand Up @@ -100,7 +100,7 @@ class ExecutionContext {
class JSHandle {
/**
* @param {!ExecutionContext} context
* @param {!Session} client
* @param {!Puppeteer.Session} client
* @param {!Object} remoteObject
*/
constructor(context, client, remoteObject) {
Expand Down Expand Up @@ -134,7 +134,7 @@ class JSHandle {
}

/**
* @return {!Property<Map<string, !ObjectHandle>>}
* @return {!Promise<Map<string, !JSHandle>>}
*/
async getProperties() {
const response = await this._client.send('Runtime.getProperties', {
Expand Down Expand Up @@ -162,7 +162,7 @@ class JSHandle {
}

/**
* @return {?ElementHandle}
* @return {?Puppeteer.ElementHandle}
*/
asElement() {
return null;
Expand Down
27 changes: 13 additions & 14 deletions lib/FrameManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const ElementHandle = require('./ElementHandle');

class FrameManager extends EventEmitter {
/**
* @param {!Session} client
* @param {!Page} page
* @param {!Puppeteer.Session} client
* @param {!Puppeteer.Page} page
*/
constructor(client, page) {
super();
Expand Down Expand Up @@ -87,7 +87,7 @@ class FrameManager extends EventEmitter {
if (isMainFrame) {
if (frame) {
// Update frame id to retain frame identity on cross-process navigation.
this._frames.delete(frame._id, frame);
this._frames.delete(frame._id);
frame._id = framePayload.id;
} else {
// Initial main frame navigation.
Expand Down Expand Up @@ -154,7 +154,6 @@ class FrameManager extends EventEmitter {
}

/**
* @param {!Frame} frame
* @return {boolean}
*/
isMainFrameLoadingFailed() {
Expand All @@ -174,7 +173,7 @@ FrameManager.Events = {
*/
class Frame {
/**
* @param {!Session} client
* @param {!Puppeteer.Session} client
* @param {?Frame} parentFrame
* @param {string} frameId
*/
Expand Down Expand Up @@ -202,9 +201,9 @@ class Frame {
}

/**
* @param {function()|string} pageFunction
* @param {Function|string} pageFunction
* @param {!Array<*>} args
* @return {!Promise<(!Object|undefined)>}
* @return {!Promise<*>}
*/
async evaluate(pageFunction, ...args) {
return this._context.evaluate(pageFunction, ...args);
Expand All @@ -225,7 +224,7 @@ class Frame {

/**
* @param {string} selector
* @param {function()|string} pageFunction
* @param {Function|string} pageFunction
* @param {!Array<*>} args
* @return {!Promise<(!Object|undefined)>}
*/
Expand Down Expand Up @@ -344,14 +343,14 @@ class Frame {
}

/**
* @param {(string|number|function())} selectorOrTimeout
* @param {(string|number|Function)} selectorOrFunctionOrTimeout
* @param {!Object=} options
* @param {!Array<*>} args
* @return {!Promise}
*/
waitFor(selectorOrFunctionOrTimeout, options = {}, ...args) {
if (helper.isString(selectorOrFunctionOrTimeout))
return this.waitForSelector(selectorOrFunctionOrTimeout, options);
return this.waitForSelector(/** @type {string} */(selectorOrFunctionOrTimeout), options);
if (helper.isNumber(selectorOrFunctionOrTimeout))
return new Promise(fulfill => setTimeout(fulfill, selectorOrFunctionOrTimeout));
if (typeof selectorOrFunctionOrTimeout === 'function')
Expand Down Expand Up @@ -387,7 +386,7 @@ class Frame {
}

/**
* @param {function()} pageFunction
* @param {Function} pageFunction
* @param {!Object=} options
* @return {!Promise}
*/
Expand Down Expand Up @@ -429,7 +428,7 @@ class WaitTask {
/**
* @param {!Frame} frame
* @param {string} predicateBody
* @param {string} polling
* @param {string|number} polling
* @param {number} timeout
*/
constructor(frame, predicateBody, polling, timeout) {
Expand Down Expand Up @@ -524,7 +523,7 @@ async function waitForPredicatePageFunction(predicateBody, polling, timeout) {
return !timedOut;

/**
* @return {!Promise<!Element>}
* @return {!Promise}
*/
function pollMutation() {
if (predicate())
Expand Down Expand Up @@ -582,4 +581,4 @@ async function waitForPredicatePageFunction(predicateBody, polling, timeout) {
}
}

module.exports = FrameManager;
module.exports = {FrameManager, Frame};
12 changes: 6 additions & 6 deletions lib/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {helper} = require('./helper');

class Keyboard {
/**
* @param {!Session} client
* @param {!Puppeteer.Session} client
*/
constructor(client) {
this._client = client;
Expand All @@ -28,10 +28,10 @@ class Keyboard {

/**
* @param {string} key
* @param {{text: (string|undefined)}} options
* @param {{text: string}=} options
*/
async down(key, options = {}) {
const text = options.text;
async down(key, options = {text: ''}) {
const {text} = options;
const autoRepeat = this._pressedKeys.has(key);
this._pressedKeys.add(key);
this._modifiers |= this._modifierBit(key);
Expand Down Expand Up @@ -118,7 +118,7 @@ class Keyboard {

class Mouse {
/**
* @param {!Session} client
* @param {Puppeteer.Session} client
* @param {!Keyboard} keyboard
*/
constructor(client, keyboard) {
Expand Down Expand Up @@ -197,7 +197,7 @@ class Mouse {

class Touchscreen {
/**
* @param {Session} client
* @param {Puppeteer.Session} client
* @param {Keyboard} keyboard
*/
constructor(client, keyboard) {
Expand Down
7 changes: 4 additions & 3 deletions lib/Launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ const path = require('path');
const removeSync = require('rimraf').sync;
const childProcess = require('child_process');
const Downloader = require('../utils/ChromiumDownloader');
const Connection = require('./Connection');
const Browser = require('./Browser');
const {Connection} = require('./Connection');
const {Browser} = require('./Browser');
const readline = require('readline');
const fs = require('fs');
const {helper} = require('./helper');
// @ts-ignore
const ChromiumRevision = require('../package.json').puppeteer.chromium_revision;

const CHROME_PROFILE_PATH = path.join(os.tmpdir(), 'puppeteer_dev_profile-');
Expand Down Expand Up @@ -178,7 +179,7 @@ class Launcher {
}

/**
* @param {!ChildProcess} chromeProcess
* @param {!Puppeteer.ChildProcess} chromeProcess
* @param {number} timeout
* @return {!Promise<string>}
*/
Expand Down
Loading