Socket
Socket
Sign inDemoInstall

puppeteer-core

Package Overview
Dependencies
11
Maintainers
5
Versions
222
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.3.0 to 4.0.0

lib/Accessibility.d.ts

39

index.js

@@ -17,38 +17,9 @@ /**

const { helper } = require('./lib/helper');
const api = require('./lib/api');
const { Page } = require('./lib/Page');
for (const className in api) {
if (typeof api[className] === 'function')
helper.installAsyncStackHooks(api[className]);
}
const { initializePuppeteer } = require('./lib/index');
// Expose alias for deprecated method.
Page.prototype.emulateMedia = Page.prototype.emulateMediaType;
const puppeteer = initializePuppeteer({
packageJson: require('./package.json'),
rootDirectory: __dirname,
});
const { Puppeteer } = require('./lib/Puppeteer');
const packageJson = require('./package.json');
let preferredRevision = packageJson.puppeteer.chromium_revision;
const isPuppeteerCore = packageJson.name === 'puppeteer-core';
// puppeteer-core ignores environment variables
const product = isPuppeteerCore
? undefined
: process.env.PUPPETEER_PRODUCT ||
process.env.npm_config_puppeteer_product ||
process.env.npm_package_config_puppeteer_product;
if (!isPuppeteerCore && product === 'firefox')
preferredRevision = packageJson.puppeteer.firefox_revision;
const puppeteer = new Puppeteer(
__dirname,
preferredRevision,
isPuppeteerCore,
product
);
// The introspection in `Helper.installAsyncStackHooks` references `Puppeteer._launcher`
// before the Puppeteer ctor is called, such that an invalid Launcher is selected at import,
// so we reset it.
puppeteer._lazyLauncher = undefined;
module.exports = puppeteer;

@@ -28,2 +28,3 @@ /**

const compileTypeScriptIfRequired = require('./typescript-if-required');
const os = require('os');

@@ -100,8 +101,10 @@ const firefoxVersions =

* @param {!Array<string>}
* @return {!Promise}
* @returns {!Promise}
*/
function onSuccess(localRevisions) {
logPolitely(
`${supportedProducts[product]} (${revisionInfo.revision}) downloaded to ${revisionInfo.folderPath}`
);
if (os.arch() !== 'arm64') {
logPolitely(
`${supportedProducts[product]} (${revisionInfo.revision}) downloaded to ${revisionInfo.folderPath}`
);
}
localRevisions = localRevisions.filter(

@@ -108,0 +111,0 @@ (revision) => revision !== revisionInfo.revision

@@ -19,6 +19,69 @@ "use strict";

exports.Accessibility = void 0;
/**
* The Accessibility class provides methods for inspecting Chromium's
* accessibility tree. The accessibility tree is used by assistive technology
* such as {@link https://en.wikipedia.org/wiki/Screen_reader | screen readers} or
* {@link https://en.wikipedia.org/wiki/Switch_access | switches}.
*
* @remarks
*
* Accessibility is a very platform-specific thing. On different platforms,
* there are different screen readers that might have wildly different output.
*
* Blink - Chrome's rendering engine - has a concept of "accessibility tree",
* which is then translated into different platform-specific APIs. Accessibility
* namespace gives users access to the Blink Accessibility Tree.
*
* Most of the accessibility tree gets filtered out when converting from Blink
* AX Tree to Platform-specific AX-Tree or by assistive technologies themselves.
* By default, Puppeteer tries to approximate this filtering, exposing only
* the "interesting" nodes of the tree.
*
* @public
*/
class Accessibility {
/**
* @internal
*/
constructor(client) {
this._client = client;
}
/**
* Captures the current state of the accessibility tree.
* The returned object represents the root accessible node of the page.
*
* @remarks
*
* **NOTE** The Chromium accessibility tree contains nodes that go unused on most platforms and by
* most screen readers. Puppeteer will discard them as well for an easier to process tree,
* unless `interestingOnly` is set to `false`.
*
* @example
* An example of dumping the entire accessibility tree:
* ```js
* const snapshot = await page.accessibility.snapshot();
* console.log(snapshot);
* ```
*
* @example
* An example of logging the focused node's name:
* ```js
* const snapshot = await page.accessibility.snapshot();
* const node = findFocusedNode(snapshot);
* console.log(node && node.name);
*
* function findFocusedNode(node) {
* if (node.focused)
* return node;
* for (const child of node.children || []) {
* const foundNode = findFocusedNode(child);
* return foundNode;
* }
* return null;
* }
* ```
*
* @returns An AXNode object represeting the snapshot.
*
*/
async snapshot(options = {}) {

@@ -25,0 +88,0 @@ const { interestingOnly = true, root = null } = options;

@@ -31,2 +31,3 @@ /**

ExecutionContext: require('./ExecutionContext').ExecutionContext,
EventEmitter: require('./EventEmitter').EventEmitter,
FileChooser: require('./FileChooser').FileChooser,

@@ -33,0 +34,0 @@ Frame: require('./FrameManager').Frame,

@@ -21,5 +21,5 @@ "use strict";

const Target_1 = require("./Target");
const EventEmitter = require("events");
const EventEmitter_1 = require("./EventEmitter");
const Events_1 = require("./Events");
class Browser extends EventEmitter {
class Browser extends EventEmitter_1.EventEmitter {
constructor(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback) {

@@ -139,3 +139,3 @@ super();

* @param {{timeout?: number}=} options
* @return {!Promise<!Target>}
* @returns {!Promise<!Target>}
*/

@@ -193,3 +193,3 @@ async waitForTarget(predicate, options = {}) {

exports.Browser = Browser;
class BrowserContext extends EventEmitter {
class BrowserContext extends EventEmitter_1.EventEmitter {
constructor(connection, browser, contextId) {

@@ -196,0 +196,0 @@ super();

@@ -17,19 +17,41 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BrowserFetcher = void 0;
const os = require("os");
const fs = require("fs");
const path = require("path");
const util = require("util");
const childProcess = require("child_process");
const https = require("https");
const http = require("http");
const extractZip = require("extract-zip");
const debug = require("debug");
const removeRecursive = require("rimraf");
const URL = require("url");
const ProxyAgent = require("https-proxy-agent");
const os = __importStar(require("os"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const util = __importStar(require("util"));
const childProcess = __importStar(require("child_process"));
const https = __importStar(require("https"));
const http = __importStar(require("http"));
const extract_zip_1 = __importDefault(require("extract-zip"));
const debug_1 = __importDefault(require("debug"));
const rimraf_1 = __importDefault(require("rimraf"));
const URL = __importStar(require("url"));
const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
const proxy_from_env_1 = require("proxy-from-env");
const helper_1 = require("./helper");
const debugFetcher = debug(`puppeteer:fetcher`);
const debugFetcher = debug_1.default(`puppeteer:fetcher`);
const downloadURLs = {

@@ -79,3 +101,3 @@ chrome: {

* @param {string} revision
* @return {string}
* @returns {string}
*/

@@ -86,2 +108,12 @@ function downloadURL(product, platform, host, revision) {

}
function handleArm64() {
fs.stat('/usr/bin/chromium-browser', function (err, stats) {
if (stats === undefined) {
console.error(`The chromium binary is not available for arm64: `);
console.error(`If you are on Ubuntu, you can install with: `);
console.error(`\n apt-get install chromium-browser\n`);
throw new Error();
}
});
}
const readdirAsync = helper_1.helper.promisify(fs.readdir.bind(fs));

@@ -148,3 +180,3 @@ const mkdirAsync = helper_1.helper.promisify(fs.mkdir.bind(fs));

* @param {?function(number, number):void} progressCallback
* @return {!Promise<!BrowserFetcher.RevisionInfo>}
* @returns {!Promise<!BrowserFetcher.RevisionInfo>}
*/

@@ -160,2 +192,6 @@ async download(revision, progressCallback) {

await mkdirAsync(this._downloadsFolder);
if (os.arch() === 'arm64') {
handleArm64();
return;
}
try {

@@ -186,3 +222,3 @@ await downloadFile(url, archivePath, progressCallback);

helper_1.assert(await existsAsync(folderPath), `Failed to remove: revision ${revision} is not downloaded`);
await new Promise((fulfill) => removeRecursive(folderPath, fulfill));
await new Promise((fulfill) => rimraf_1.default(folderPath, fulfill));
}

@@ -236,3 +272,3 @@ revisionInfo(revision) {

* @param {string} revision
* @return {string}
* @returns {string}
*/

@@ -258,3 +294,3 @@ _getFolderPath(revision) {

* @param {?function(number, number):void} progressCallback
* @return {!Promise}
* @returns {!Promise}
*/

@@ -297,3 +333,3 @@ function downloadFile(url, destinationPath, progressCallback) {

if (archivePath.endsWith('.zip'))
return extractZip(archivePath, { dir: folderPath });
return extract_zip_1.default(archivePath, { dir: folderPath });
else if (archivePath.endsWith('.tar.bz2'))

@@ -309,3 +345,3 @@ return extractTar(archivePath, folderPath);

* @param {string} folderPath
* @return {!Promise<?Error>}
* @returns {!Promise<?Error>}
*/

@@ -322,5 +358,2 @@ function extractTar(tarPath, folderPath) {

const readStream = fs.createReadStream(tarPath);
readStream.on('data', () => {
process.stdout.write('\rExtracting...');
});
readStream.pipe(bzip()).pipe(tarStream);

@@ -334,3 +367,3 @@ });

* @param {string} folderPath
* @return {!Promise<?Error>}
* @returns {!Promise<?Error>}
*/

@@ -403,3 +436,3 @@ function installDMG(dmgPath, folderPath) {

};
options.agent = new ProxyAgent(proxyOptions);
options.agent = new https_proxy_agent_1.default(proxyOptions);
options.rejectUnauthorized = false;

@@ -406,0 +439,0 @@ }

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -21,6 +24,7 @@ exports.CDPSession = exports.Connection = void 0;

const Events_1 = require("./Events");
const debug = require("debug");
const debugProtocol = debug('puppeteer:protocol');
const EventEmitter = require("events");
class Connection extends EventEmitter {
const debug_1 = __importDefault(require("debug"));
const debugProtocolSend = debug_1.default('puppeteer:protocol:SEND ►');
const debugProtocolReceive = debug_1.default('puppeteer:protocol:RECV ◀');
const EventEmitter_1 = require("./EventEmitter");
class Connection extends EventEmitter_1.EventEmitter {
constructor(url, transport, delay = 0) {

@@ -43,3 +47,3 @@ super();

* @param {string} sessionId
* @return {?CDPSession}
* @returns {?CDPSession}
*/

@@ -61,3 +65,3 @@ session(sessionId) {

message = JSON.stringify(Object.assign({}, message, { id }));
debugProtocol('SEND ► ' + message);
debugProtocolSend(message);
this._transport.send(message);

@@ -69,3 +73,3 @@ return id;

await new Promise((f) => setTimeout(f, this._delay));
debugProtocol('◀ RECV ' + message);
debugProtocolReceive(message);
const object = JSON.parse(message);

@@ -124,3 +128,3 @@ if (object.method === 'Target.attachedToTarget') {

* @param {Protocol.Target.TargetInfo} targetInfo
* @return {!Promise<!CDPSession>}
* @returns {!Promise<!CDPSession>}
*/

@@ -136,3 +140,3 @@ async createSession(targetInfo) {

exports.Connection = Connection;
class CDPSession extends EventEmitter {
class CDPSession extends EventEmitter_1.EventEmitter {
constructor(connection, targetType, sessionId) {

@@ -195,3 +199,3 @@ super();

* @param {{error: {message: string, data: any}}} object
* @return {!Error}
* @returns {!Error}
*/

@@ -207,3 +211,3 @@ function createProtocolError(error, method, object) {

* @param {string} message
* @return {!Error}
* @returns {!Error}
*/

@@ -210,0 +214,0 @@ function rewriteError(error, message) {

@@ -18,51 +18,77 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Dialog = exports.DialogType = void 0;
exports.Dialog = void 0;
const helper_1 = require("./helper");
/* TODO(jacktfranklin): protocol.d.ts defines this
* so let's ditch this and avoid the duplication
/**
* Dialog instances are dispatched by the {@link Page} via the `dialog` event.
*
* @remarks
*
* @example
* ```js
* const puppeteer = require('puppeteer');
*
* (async () => {
* const browser = await puppeteer.launch();
* const page = await browser.newPage();
* page.on('dialog', async dialog => {
* console.log(dialog.message());
* await dialog.dismiss();
* await browser.close();
* });
* page.evaluate(() => alert('1'));
* })();
* ```
*/
var DialogType;
(function (DialogType) {
DialogType["Alert"] = "alert";
DialogType["BeforeUnload"] = "beforeunload";
DialogType["Confirm"] = "confirm";
DialogType["Prompt"] = "prompt";
})(DialogType = exports.DialogType || (exports.DialogType = {}));
let Dialog = /** @class */ (() => {
class Dialog {
constructor(client, type, message, defaultValue = '') {
this._handled = false;
this._client = client;
this._type = type;
this._message = message;
this._defaultValue = defaultValue;
}
type() {
return this._type;
}
message() {
return this._message;
}
defaultValue() {
return this._defaultValue;
}
async accept(promptText) {
helper_1.assert(!this._handled, 'Cannot accept dialog which is already handled!');
this._handled = true;
await this._client.send('Page.handleJavaScriptDialog', {
accept: true,
promptText: promptText,
});
}
async dismiss() {
helper_1.assert(!this._handled, 'Cannot dismiss dialog which is already handled!');
this._handled = true;
await this._client.send('Page.handleJavaScriptDialog', {
accept: false,
});
}
class Dialog {
/**
* @internal
*/
constructor(client, type, message, defaultValue = '') {
this._handled = false;
this._client = client;
this._type = type;
this._message = message;
this._defaultValue = defaultValue;
}
Dialog.Type = DialogType;
return Dialog;
})();
/**
* @returns The type of the dialog.
*/
type() {
return this._type;
}
/**
* @returns The message displayed in the dialog.
*/
message() {
return this._message;
}
/**
* @returns The default value of the prompt, or an empty string if the dialog is not a `prompt`.
*/
defaultValue() {
return this._defaultValue;
}
/**
* @param promptText - optional text that will be entered in the dialog prompt. Has no effect if the dialog's type is not `prompt`.
* @returns A promise that resolves when the dialog has been accepted.
*/
async accept(promptText) {
helper_1.assert(!this._handled, 'Cannot accept dialog which is already handled!');
this._handled = true;
await this._client.send('Page.handleJavaScriptDialog', {
accept: true,
promptText: promptText,
});
}
/**
* @returns A promise which will resolve once the dialog has been dismissed
*/
async dismiss() {
helper_1.assert(!this._handled, 'Cannot dismiss dialog which is already handled!');
this._handled = true;
await this._client.send('Page.handleJavaScriptDialog', {
accept: false,
});
}
}
exports.Dialog = Dialog;

@@ -17,5 +17,24 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DOMWorld = void 0;
const fs = require("fs");
const fs = __importStar(require("fs"));
const helper_1 = require("./helper");

@@ -67,3 +86,3 @@ const LifecycleWatcher_1 = require("./LifecycleWatcher");

/**
* @return {!Promise<!ExecutionContext>}
* @returns {!Promise<!ExecutionContext>}
*/

@@ -78,3 +97,3 @@ executionContext() {

* @param {!Array<*>} args
* @return {!Promise<!JSHandle>}
* @returns {!Promise<!JSHandle>}
*/

@@ -88,3 +107,3 @@ async evaluateHandle(pageFunction, ...args) {

* @param {!Array<*>} args
* @return {!Promise<*>}
* @returns {!Promise<*>}
*/

@@ -97,3 +116,3 @@ async evaluate(pageFunction, ...args) {

* @param {string} selector
* @return {!Promise<?ElementHandle>}
* @returns {!Promise<?ElementHandle>}
*/

@@ -130,3 +149,3 @@ async $(selector) {

* @param {string} selector
* @return {!Promise<!Array<!ElementHandle>>}
* @returns {!Promise<!Array<!ElementHandle>>}
*/

@@ -168,3 +187,3 @@ async $$(selector) {

* @param {!{url?: string, path?: string, content?: string, type?: string}} options
* @return {!Promise<!ElementHandle>}
* @returns {!Promise<!ElementHandle>}
*/

@@ -332,3 +351,3 @@ async addScriptTag(options) {

* @param {boolean} waitForHidden
* @return {?Node|boolean}
* @returns {?Node|boolean}
*/

@@ -462,3 +481,3 @@ function predicate(selectorOrXPath, isXPath, waitForVisible, waitForHidden) {

/**
* @return {!Promise<*>}
* @returns {!Promise<*>}
*/

@@ -465,0 +484,0 @@ async function pollMutation() {

@@ -108,3 +108,3 @@ "use strict";

* @param {*} arg
* @return {*}
* @returns {*}
* @this {ExecutionContext}

@@ -111,0 +111,0 @@ */

@@ -19,3 +19,3 @@ "use strict";

exports.Frame = exports.FrameManager = void 0;
const EventEmitter = require("events");
const EventEmitter_1 = require("./EventEmitter");
const helper_1 = require("./helper");

@@ -28,3 +28,3 @@ const Events_1 = require("./Events");

const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';
class FrameManager extends EventEmitter {
class FrameManager extends EventEmitter_1.EventEmitter {
constructor(client, page, ignoreHTTPSErrors, timeoutSettings) {

@@ -31,0 +31,0 @@ super();

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -20,4 +42,4 @@ exports.helper = exports.assert = exports.debugError = void 0;

const Errors_1 = require("./Errors");
const debug = require("debug");
const fs = require("fs");
const debug_1 = __importDefault(require("debug"));
const fs = __importStar(require("fs"));
const util_1 = require("util");

@@ -27,3 +49,3 @@ const openAsync = util_1.promisify(fs.open);

const closeAsync = util_1.promisify(fs.close);
exports.debugError = debug('puppeteer:error');
exports.debugError = debug_1.default('puppeteer:error');
function assert(value, message) {

@@ -30,0 +52,0 @@ if (!value)

@@ -55,3 +55,3 @@ "use strict";

/**
* @return {?{errorText: string}}
* @returns {?{errorText: string}}
*/

@@ -58,0 +58,0 @@ failure() {

@@ -156,3 +156,3 @@ "use strict";

return false;
}, this._page._javascriptEnabled);
}, this._page.isJavaScriptEnabled());
if (error)

@@ -326,3 +326,3 @@ throw new Error(error);

/**
* @return {!Promise<?BoxModel>}
* @returns {!Promise<?BoxModel>}
*/

@@ -329,0 +329,0 @@ async boxModel() {

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -18,8 +37,8 @@ /**

*/
const os = require("os");
const path = require("path");
const http = require("http");
const https = require("https");
const URL = require("url");
const fs = require("fs");
const os = __importStar(require("os"));
const path = __importStar(require("path"));
const http = __importStar(require("http"));
const https = __importStar(require("https"));
const URL = __importStar(require("url"));
const fs = __importStar(require("fs"));
const BrowserFetcher_1 = require("./BrowserFetcher");

@@ -57,3 +76,6 @@ const Connection_1 = require("./Connection");

let chromeExecutable = executablePath;
if (!executablePath) {
if (os.arch() === 'arm64') {
chromeExecutable = '/usr/bin/chromium-browser';
}
else if (!executablePath) {
const { missingText, executablePath } = resolveExecutablePath(this);

@@ -92,3 +114,3 @@ if (missingText)

* @param {!Launcher.ChromeArgOptions=} options
* @return {!Array<string>}
* @returns {!Array<string>}
*/

@@ -95,0 +117,0 @@ defaultArgs(options = {}) {

@@ -17,7 +17,29 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BrowserRunner = void 0;
const debug = require("debug");
const removeFolder = require("rimraf");
const childProcess = require("child_process");
const debug_1 = __importDefault(require("debug"));
const rimraf_1 = __importDefault(require("rimraf"));
const childProcess = __importStar(require("child_process"));
const helper_1 = require("../helper");

@@ -27,6 +49,10 @@ const Connection_1 = require("../Connection");

const PipeTransport_1 = require("../PipeTransport");
const readline = require("readline");
const readline = __importStar(require("readline"));
const Errors_1 = require("../Errors");
const removeFolderAsync = helper_1.helper.promisify(removeFolder);
const debugLauncher = debug('puppeteer:launcher');
const removeFolderAsync = helper_1.helper.promisify(rimraf_1.default);
const debugLauncher = debug_1.default('puppeteer:launcher');
const PROCESS_ERROR_EXPLANATION = `Puppeteer was unable to kill the process which ran the browser binary.
This means that, on future Puppeteer launches, Puppeteer might not be able to launch the browser.
Please check your open processes and ensure that the browser processes that Puppeteer launched have been killed.
If you think this is a bug, please report it on the Puppeteer issue tracker.`;
class BrowserRunner {

@@ -42,3 +68,3 @@ constructor(executablePath, processArguments, tempDirectory) {

}
start(options = {}) {
start(options) {
const { handleSIGINT, handleSIGTERM, handleSIGHUP, dumpio, env, pipe, } = options;

@@ -97,3 +123,2 @@ let stdio = ['pipe', 'pipe', 'pipe'];

return Promise.resolve();
helper_1.helper.removeEventListeners(this._listeners);
if (this._tempDirectory) {

@@ -109,22 +134,27 @@ this.kill();

}
// Cleanup this listener last, as that makes sure the full callback runs. If we
// perform this earlier, then the previous function calls would not happen.
helper_1.helper.removeEventListeners(this._listeners);
return this._processClosing;
}
kill() {
helper_1.helper.removeEventListeners(this._listeners);
if (this.proc && this.proc.pid && !this.proc.killed && !this._closed) {
// Attempt to remove temporary profile directory to avoid littering.
try {
rimraf_1.default.sync(this._tempDirectory);
}
catch (error) { }
// If the process failed to launch (for example if the browser executable path
// is invalid), then the process does not get a pid assigned. A call to
// `proc.kill` would error, as the `pid` to-be-killed can not be found.
if (this.proc && this.proc.pid && !this.proc.killed) {
try {
if (process.platform === 'win32')
childProcess.execSync(`taskkill /pid ${this.proc.pid} /T /F`);
else
process.kill(-this.proc.pid, 'SIGKILL');
this.proc.kill('SIGKILL');
}
catch (error) {
// the process might have already stopped
throw new Error(`${PROCESS_ERROR_EXPLANATION}\nError cause: ${error.stack}`);
}
}
// Attempt to remove temporary profile directory to avoid littering.
try {
removeFolder.sync(this._tempDirectory);
}
catch (error) { }
// Cleanup this listener last, as that makes sure the full callback runs. If we
// perform this earlier, then the previous function calls would not happen.
helper_1.helper.removeEventListeners(this._listeners);
}

@@ -131,0 +161,0 @@ async setupConnection(options) {

@@ -123,3 +123,3 @@ "use strict";

* @param {!Array<string>} expectedLifecycle
* @return {boolean}
* @returns {boolean}
*/

@@ -126,0 +126,0 @@ function checkLifecycle(frame, expectedLifecycle) {

@@ -19,3 +19,3 @@ "use strict";

*/
const EventEmitter = require("events");
const EventEmitter_1 = require("./EventEmitter");
const helper_1 = require("./helper");

@@ -25,3 +25,3 @@ const Events_1 = require("./Events");

const HTTPResponse_1 = require("./HTTPResponse");
class NetworkManager extends EventEmitter {
class NetworkManager extends EventEmitter_1.EventEmitter {
constructor(client, ignoreHTTPSErrors, frameManager) {

@@ -28,0 +28,0 @@ super();

@@ -17,7 +17,26 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Page = void 0;
const fs = require("fs");
const EventEmitter = require("events");
const mime = require("mime");
const fs = __importStar(require("fs"));
const EventEmitter_1 = require("./EventEmitter");
const mime = __importStar(require("mime"));
const Events_1 = require("./Events");

@@ -71,3 +90,45 @@ const Connection_1 = require("./Connection");

}
class Page extends EventEmitter {
/**
* Page provides methods to interact with a single tab or [extension background page](https://developer.chrome.com/extensions/background_pages) in Chromium. One [Browser] instance might have multiple [Page] instances.
*
* @remarks
*
* @example
* This example creates a page, navigates it to a URL, and then * saves a screenshot:
* ```js
* const puppeteer = require('puppeteer');
*
* (async () => {
* const browser = await puppeteer.launch();
* const page = await browser.newPage();
* await page.goto('https://example.com');
* await page.screenshot({path: 'screenshot.png'});
* await browser.close();
* })();
* ```
*
* The Page class extends from Puppeteer's {@link EventEmitter } class and will emit various events which are documented in the {@link PageEmittedEvents} enum.
*
* @example
* This example logs a message for a single page `load` event:
* ```js
* page.once('load', () => console.log('Page loaded!'));
* ```
*
* To unsubscribe from events use the `off` method:
*
* ```js
* function logRequest(interceptedRequest) {
* console.log('A request was made:', interceptedRequest.url());
* }
* page.on('request', logRequest);
* // Sometime later...
* page.off('request', logRequest);
* ```
* @public
*/
class Page extends EventEmitter_1.EventEmitter {
/**
* @internal
*/
constructor(client, target, ignoreHTTPSErrors) {

@@ -107,3 +168,3 @@ super();

this._workers.set(event.sessionId, worker);
this.emit(Events_1.Events.Page.WorkerCreated, worker);
this.emit("workercreated" /* WorkerCreated */, worker);
});

@@ -141,2 +202,5 @@ client.on('Target.detachedFromTarget', (event) => {

}
/**
* @internal
*/
static async create(client, target, ignoreHTTPSErrors, defaultViewport) {

@@ -173,2 +237,5 @@ const page = new Page(client, target, ignoreHTTPSErrors);

}
isJavaScriptEnabled() {
return this._javascriptEnabled;
}
async waitForFileChooser(options = {}) {

@@ -468,10 +535,11 @@ if (!this._fileChooserInterceptors.size)

let dialogType = null;
if (event.type === 'alert')
dialogType = Dialog_1.Dialog.Type.Alert;
else if (event.type === 'confirm')
dialogType = Dialog_1.Dialog.Type.Confirm;
else if (event.type === 'prompt')
dialogType = Dialog_1.Dialog.Type.Prompt;
else if (event.type === 'beforeunload')
dialogType = Dialog_1.Dialog.Type.BeforeUnload;
const validDialogTypes = new Set([
'alert',
'confirm',
'prompt',
'beforeunload',
]);
if (validDialogTypes.has(event.type)) {
dialogType = event.type;
}
helper_1.assert(dialogType, 'Unknown javascript dialog type: ' + event.type);

@@ -478,0 +546,0 @@ const dialog = new Dialog_1.Dialog(this._client, dialogType, event.message, event.defaultPrompt);

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -19,7 +22,11 @@ exports.Puppeteer = void 0;

*/
const Launcher_1 = require("./Launcher");
const Launcher_1 = __importDefault(require("./Launcher"));
const BrowserFetcher_1 = require("./BrowserFetcher");
const Errors_1 = require("./Errors");
const DeviceDescriptors_1 = require("./DeviceDescriptors");
const QueryHandler = require("./QueryHandler");
const QueryHandler_1 = require("./QueryHandler");
/**
* The main Puppeteer class
* @public
*/
class Puppeteer {

@@ -92,17 +99,17 @@ constructor(projectRoot, preferredRevision, isPuppeteerCore, productName) {

__experimental_registerCustomQueryHandler(name, queryHandler) {
QueryHandler.registerCustomQueryHandler(name, queryHandler);
QueryHandler_1.registerCustomQueryHandler(name, queryHandler);
}
// eslint-disable-next-line @typescript-eslint/camelcase
__experimental_unregisterCustomQueryHandler(name) {
QueryHandler.unregisterCustomQueryHandler(name);
QueryHandler_1.unregisterCustomQueryHandler(name);
}
// eslint-disable-next-line @typescript-eslint/camelcase
__experimental_customQueryHandlers() {
return QueryHandler.customQueryHandlers();
return QueryHandler_1.customQueryHandlers();
}
// eslint-disable-next-line @typescript-eslint/camelcase
__experimental_clearQueryHandlers() {
QueryHandler.clearQueryHandlers();
QueryHandler_1.clearQueryHandlers();
}
}
exports.Puppeteer = Puppeteer;

@@ -60,8 +60,1 @@ "use strict";

exports.getQueryHandlerAndSelector = getQueryHandlerAndSelector;
module.exports = {
registerCustomQueryHandler,
unregisterCustomQueryHandler,
customQueryHandlers,
getQueryHandlerAndSelector,
clearQueryHandlers,
};
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebSocketTransport = void 0;
/**
* Copyright 2018 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const NodeWebSocket = require("ws");
const ws_1 = __importDefault(require("ws"));
class WebSocketTransport {

@@ -38,3 +26,3 @@ constructor(ws) {

return new Promise((resolve, reject) => {
const ws = new NodeWebSocket(url, [], {
const ws = new ws_1.default(url, [], {
perMessageDeflate: false,

@@ -41,0 +29,0 @@ maxPayload: 256 * 1024 * 1024,

@@ -19,7 +19,7 @@ "use strict";

*/
const events_1 = require("events");
const EventEmitter_1 = require("./EventEmitter");
const helper_1 = require("./helper");
const ExecutionContext_1 = require("./ExecutionContext");
const JSHandle_1 = require("./JSHandle");
class WebWorker extends events_1.EventEmitter {
class WebWorker extends EventEmitter_1.EventEmitter {
constructor(client, url, consoleAPICalled, exceptionThrown) {

@@ -26,0 +26,0 @@ super();

{
"name": "puppeteer-core",
"version": "3.3.0",
"version": "4.0.0",
"description": "A high-level API to control headless Chrome over the DevTools Protocol",

@@ -21,3 +21,3 @@ "main": "index.js",

"test-doclint": "mocha --config mocha-config/doclint-tests.js",
"test": "npm run tsc && npm run lint --silent && npm run coverage && npm run test-doclint && npm run test-types",
"test": "npm run tsc && npm run lint --silent && npm run unit-with-coverage && npm run test-doclint && npm run test-types",
"prepare": "node typescript-if-required.js",

@@ -30,7 +30,10 @@ "prepublishOnly": "npm run tsc",

"doc": "node utils/doclint/cli.js",
"tsc": "tsc --version && tsc -p . && cp src/protocol.d.ts lib/",
"clean-lib": "rm -rf lib",
"tsc": "npm run clean-lib && tsc --version && tsc -p . && cp src/protocol.d.ts lib/",
"apply-next-version": "node utils/apply_next_version.js",
"update-protocol-d-ts": "node utils/protocol-types-generator update",
"compare-protocol-d-ts": "node utils/protocol-types-generator compare",
"test-install": "scripts/test-install.sh"
"test-install": "scripts/test-install.sh",
"generate-docs": "npm run tsc && api-extractor run --local --verbose && api-documenter markdown -i temp -o new-docs",
"ensure-new-docs-up-to-date": "npm run generate-docs && exit `git status --porcelain | head -255 | wc -l`"
},

@@ -52,2 +55,3 @@ "files": [

"mime": "^2.0.3",
"mitt": "^2.0.1",
"progress": "^2.0.1",

@@ -61,2 +65,4 @@ "proxy-from-env": "^1.0.0",

"devDependencies": {
"@microsoft/api-documenter": "^7.8.8",
"@microsoft/api-extractor": "^7.8.8",
"@types/debug": "0.0.31",

@@ -63,0 +69,0 @@ "@types/mime": "^2.0.0",

@@ -9,3 +9,3 @@ # Puppeteer

###### [API](https://github.com/puppeteer/puppeteer/blob/v3.3.0/docs/api.md) | [FAQ](#faq) | [Contributing](https://github.com/puppeteer/puppeteer/blob/master/CONTRIBUTING.md) | [Troubleshooting](https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md)
###### [API](https://github.com/puppeteer/puppeteer/blob/v4.0.0/docs/api.md) | [FAQ](#faq) | [Contributing](https://github.com/puppeteer/puppeteer/blob/master/CONTRIBUTING.md) | [Troubleshooting](https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md)

@@ -41,3 +41,3 @@ > Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the [DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/). Puppeteer runs [headless](https://developers.google.com/web/updates/2017/04/headless-chrome) by default, but can be configured to run full (non-headless) Chrome or Chromium.

Note: When you install Puppeteer, it downloads a recent version of Chromium (~170MB Mac, ~282MB Linux, ~280MB Win) that is guaranteed to work with the API. To skip the download, or to download a different browser, see [Environment variables](https://github.com/puppeteer/puppeteer/blob/v3.3.0/docs/api.md#environment-variables).
Note: When you install Puppeteer, it downloads a recent version of Chromium (~170MB Mac, ~282MB Linux, ~280MB Win) that is guaranteed to work with the API. To skip the download, or to download a different browser, see [Environment variables](https://github.com/puppeteer/puppeteer/blob/v4.0.0/docs/api.md#environment-variables).

@@ -68,3 +68,3 @@

Puppeteer will be familiar to people using other browser testing frameworks. You create an instance
of `Browser`, open pages, and then manipulate them with [Puppeteer's API](https://github.com/puppeteer/puppeteer/blob/v3.3.0/docs/api.md#).
of `Browser`, open pages, and then manipulate them with [Puppeteer's API](https://github.com/puppeteer/puppeteer/blob/v4.0.0/docs/api.md#).

@@ -94,3 +94,3 @@ **Example** - navigating to https://example.com and saving a screenshot as *example.png*:

Puppeteer sets an initial page size to 800×600px, which defines the screenshot size. The page size can be customized with [`Page.setViewport()`](https://github.com/puppeteer/puppeteer/blob/v3.3.0/docs/api.md#pagesetviewportviewport).
Puppeteer sets an initial page size to 800×600px, which defines the screenshot size. The page size can be customized with [`Page.setViewport()`](https://github.com/puppeteer/puppeteer/blob/v4.0.0/docs/api.md#pagesetviewportviewport).

@@ -120,3 +120,3 @@ **Example** - create a PDF.

See [`Page.pdf()`](https://github.com/puppeteer/puppeteer/blob/v3.3.0/docs/api.md#pagepdfoptions) for more information about creating pdfs.
See [`Page.pdf()`](https://github.com/puppeteer/puppeteer/blob/v4.0.0/docs/api.md#pagepdfoptions) for more information about creating pdfs.

@@ -156,3 +156,3 @@ **Example** - evaluate script in the context of the page

See [`Page.evaluate()`](https://github.com/puppeteer/puppeteer/blob/v3.3.0/docs/api.md#pageevaluatepagefunction-args) for more information on `evaluate` and related methods like `evaluateOnNewDocument` and `exposeFunction`.
See [`Page.evaluate()`](https://github.com/puppeteer/puppeteer/blob/v4.0.0/docs/api.md#pageevaluatepagefunction-args) for more information on `evaluate` and related methods like `evaluateOnNewDocument` and `exposeFunction`.

@@ -166,3 +166,3 @@ <!-- [END getstarted] -->

Puppeteer launches Chromium in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). To launch a full version of Chromium, set the [`headless` option](https://github.com/puppeteer/puppeteer/blob/v3.3.0/docs/api.md#puppeteerlaunchoptions) when launching a browser:
Puppeteer launches Chromium in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). To launch a full version of Chromium, set the [`headless` option](https://github.com/puppeteer/puppeteer/blob/v4.0.0/docs/api.md#puppeteerlaunchoptions) when launching a browser:

@@ -183,3 +183,3 @@ ```js

You can also use Puppeteer with Firefox Nightly (experimental support). See [`Puppeteer.launch()`](https://github.com/puppeteer/puppeteer/blob/v3.3.0/docs/api.md#puppeteerlaunchoptions) for more information.
You can also use Puppeteer with Firefox Nightly (experimental support). See [`Puppeteer.launch()`](https://github.com/puppeteer/puppeteer/blob/v4.0.0/docs/api.md#puppeteerlaunchoptions) for more information.

@@ -196,3 +196,3 @@ See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for a description of the differences between Chromium and Chrome. [`This article`](https://chromium.googlesource.com/chromium/src/+/master/docs/chromium_browser_vs_google_chrome.md) describes some differences for Linux users.

- [API Documentation](https://github.com/puppeteer/puppeteer/blob/v3.3.0/docs/api.md)
- [API Documentation](https://github.com/puppeteer/puppeteer/blob/v4.0.0/docs/api.md)
- [Examples](https://github.com/puppeteer/puppeteer/tree/master/examples/)

@@ -324,3 +324,3 @@ - [Community list of Puppeteer resources](https://github.com/transitive-bullshit/awesome-puppeteer)

From Puppeteer v2.1.0 onwards you can specify [`puppeteer.launch({product: 'firefox'})`](https://github.com/puppeteer/puppeteer/blob/v3.3.0/docs/api.md#puppeteerlaunchoptions) to run your Puppeteer scripts in Firefox Nightly, without any additional custom patches. While [an older experiment](https://www.npmjs.com/package/puppeteer-firefox) required a patched version of Firefox, [the current approach](https://wiki.mozilla.org/Remote) works with “stock” Firefox.
From Puppeteer v2.1.0 onwards you can specify [`puppeteer.launch({product: 'firefox'})`](https://github.com/puppeteer/puppeteer/blob/v4.0.0/docs/api.md#puppeteerlaunchoptions) to run your Puppeteer scripts in Firefox Nightly, without any additional custom patches. While [an older experiment](https://www.npmjs.com/package/puppeteer-firefox) required a patched version of Firefox, [the current approach](https://wiki.mozilla.org/Remote) works with “stock” Firefox.

@@ -421,3 +421,3 @@ We will continue to collaborate with other browser vendors to bring Puppeteer support to browsers such as Safari.

* Puppeteer is bundled with Chromium — not Chrome — and so by default, it inherits all of [Chromium's media-related limitations](https://www.chromium.org/audio-video). This means that Puppeteer does not support licensed formats such as AAC or H.264. (However, it is possible to force Puppeteer to use a separately-installed version Chrome instead of Chromium via the [`executablePath` option to `puppeteer.launch`](https://github.com/puppeteer/puppeteer/blob/v3.3.0/docs/api.md#puppeteerlaunchoptions). You should only use this configuration if you need an official release of Chrome that supports these media formats.)
* Puppeteer is bundled with Chromium — not Chrome — and so by default, it inherits all of [Chromium's media-related limitations](https://www.chromium.org/audio-video). This means that Puppeteer does not support licensed formats such as AAC or H.264. (However, it is possible to force Puppeteer to use a separately-installed version Chrome instead of Chromium via the [`executablePath` option to `puppeteer.launch`](https://github.com/puppeteer/puppeteer/blob/v4.0.0/docs/api.md#puppeteerlaunchoptions). You should only use this configuration if you need an official release of Chrome that supports these media formats.)
* Since Puppeteer (in all configurations) controls a desktop version of Chromium/Chrome, features that are only supported by the mobile version of Chrome are not supported. This means that Puppeteer [does not support HTTP Live Streaming (HLS)](https://caniuse.com/#feat=http-live-streaming).

@@ -424,0 +424,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc