Socket
Socket
Sign inDemoInstall

@puppeteer/browsers

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@puppeteer/browsers - npm Package Compare versions

Comparing version 2.3.1 to 2.4.0

20

lib/cjs/browser-data/firefox.js

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

function resolveDownloadUrl(platform, buildId, baseUrl) {
const [channel, resolvedBuildId] = parseBuildId(buildId);
const [channel] = parseBuildId(buildId);
switch (channel) {

@@ -79,5 +79,10 @@ case FirefoxChannel.NIGHTLY:

}
return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
}
exports.resolveDownloadUrl = resolveDownloadUrl;
function resolveDownloadPath(platform, buildId) {
const [channel, resolvedBuildId] = parseBuildId(buildId);
switch (channel) {
case FirefoxChannel.NIGHTLY:
return `${baseUrl}/${resolveDownloadPath(platform, resolvedBuildId).join('/')}`;
return [archiveNightly(platform, resolvedBuildId)];
case FirefoxChannel.DEVEDITION:

@@ -87,9 +92,10 @@ case FirefoxChannel.BETA:

case FirefoxChannel.ESR:
return `${baseUrl}/${resolvedBuildId}/${platformName(platform)}/en-US/${archive(platform, resolvedBuildId)}`;
return [
resolvedBuildId,
platformName(platform),
'en-US',
archive(platform, resolvedBuildId),
];
}
}
exports.resolveDownloadUrl = resolveDownloadUrl;
function resolveDownloadPath(platform, buildId) {
return [archiveNightly(platform, buildId)];
}
exports.resolveDownloadPath = resolveDownloadPath;

@@ -96,0 +102,0 @@ function relativeExecutablePath(platform, buildId) {

@@ -138,2 +138,7 @@ "use strict";

}
yargs.option('install-deps', {
type: 'boolean',
desc: 'Whether to attempt installing system dependencies (only supported on Linux, requires root privileges).',
default: false,
});
yargs.example('$0 install chrome', `Install the ${latestOrPinned} available build of the Chrome browser.`);

@@ -288,2 +293,3 @@ yargs.example('$0 install chrome@latest', 'Install the latest available build for the Chrome browser.');

buildIdAlias: originalBuildId !== args.browser.buildId ? originalBuildId : undefined,
installDeps: args.installDeps,
});

@@ -290,0 +296,0 @@ console.log(`${args.browser.name}@${args.browser.buildId} ${(0, launch_js_1.computeExecutablePath)({

@@ -63,4 +63,19 @@ /**

forceFallbackForTesting?: boolean;
/**
* Whether to attempt to install system-level dependencies required
* for the browser.
*
* Only supported for Chrome on Debian or Ubuntu.
* Requires system-level privileges to run `apt-get`.
*
* @defaultValue `false`
*/
installDeps?: boolean;
}
/**
* Downloads and unpacks the browser archive according to the
* {@link InstallOptions}.
*
* @returns a {@link InstalledBrowser} instance.
*
* @public

@@ -72,2 +87,7 @@ */

/**
* Downloads the browser archive according to the {@link InstallOptions} without
* unpacking.
*
* @returns the absolute path to the archive.
*
* @public

@@ -74,0 +94,0 @@ */

@@ -93,2 +93,33 @@ "use strict";

exports.install = install;
async function installDeps(installedBrowser) {
if (process.platform !== 'linux' ||
installedBrowser.platform !== browser_data_js_1.BrowserPlatform.LINUX) {
return;
}
// Currently, only Debian-like deps are supported.
const depsPath = path_1.default.join(path_1.default.dirname(installedBrowser.executablePath), 'deb.deps');
if (!(0, fs_1.existsSync)(depsPath)) {
debugInstall(`deb.deps file was not found at ${depsPath}`);
return;
}
const data = (0, fs_1.readFileSync)(depsPath, 'utf-8').split('\n').join(',');
if (process.getuid?.() !== 0) {
throw new Error('Installing system dependencies requires root privileges');
}
let result = (0, child_process_1.spawnSync)('apt-get', ['-v']);
if (result.status !== 0) {
throw new Error('Failed to install system dependencies: apt-get does not seem to be available');
}
debugInstall(`Trying to install dependencies: ${data}`);
result = (0, child_process_1.spawnSync)('apt-get', [
'satisfy',
'-y',
data,
'--no-install-recommends',
]);
if (result.status !== 0) {
throw new Error(`Failed to install system dependencies: status=${result.status},error=${result.error},stdout=${result.stdout.toString('utf8')},stderr=${result.stderr.toString('utf8')}`);
}
debugInstall(`Installed system dependencies ${data}`);
}
async function installUrl(url, options) {

@@ -125,2 +156,5 @@ options.platform ??= (0, detectPlatform_js_1.detectBrowserPlatform)();

await runSetup(installedBrowser);
if (options.installDeps) {
await installDeps(installedBrowser);
}
return installedBrowser;

@@ -151,2 +185,5 @@ }

await runSetup(installedBrowser);
if (options.installDeps) {
await installDeps(installedBrowser);
}
return installedBrowser;

@@ -153,0 +190,0 @@ }

@@ -65,14 +65,64 @@ /**

export interface LaunchOptions {
/**
* Absolute path to the browser's executable.
*/
executablePath: string;
/**
* Configures stdio streams to open two additional streams for automation over
* those streams instead of WebSocket.
*
* @defaultValue `false`.
*/
pipe?: boolean;
/**
* If true, forwards the browser's process stdout and stderr to the Node's
* process stdout and stderr.
*
* @defaultValue `false`.
*/
dumpio?: boolean;
/**
* Additional arguments to pass to the executable when launching.
*/
args?: string[];
/**
* Environment variables to set for the browser process.
*/
env?: Record<string, string | undefined>;
/**
* Handles SIGINT in the Node process and tries to kill the browser process.
*
* @defaultValue `true`.
*/
handleSIGINT?: boolean;
/**
* Handles SIGTERM in the Node process and tries to gracefully close the browser
* process.
*
* @defaultValue `true`.
*/
handleSIGTERM?: boolean;
/**
* Handles SIGHUP in the Node process and tries to gracefully close the browser process.
*
* @defaultValue `true`.
*/
handleSIGHUP?: boolean;
/**
* Whether to spawn process in the {@link https://nodejs.org/api/child_process.html#optionsdetached | detached}
* mode.
*
* @defaultValue `true` except on Windows.
*/
detached?: boolean;
/**
* A callback to run after the browser process exits or before the process
* will be closed via the {@link Process.close} call (including when handling
* signals). The callback is only run once.
*/
onExit?: () => Promise<void>;
}
/**
* Launches a browser process according to {@link LaunchOptions}.
*
* @public

@@ -79,0 +129,0 @@ */

@@ -47,2 +47,4 @@ "use strict";

/**
* Launches a browser process according to {@link LaunchOptions}.
*
* @public

@@ -49,0 +51,0 @@ */

@@ -57,3 +57,3 @@ /**

export function resolveDownloadUrl(platform, buildId, baseUrl) {
const [channel, resolvedBuildId] = parseBuildId(buildId);
const [channel] = parseBuildId(buildId);
switch (channel) {

@@ -73,5 +73,9 @@ case FirefoxChannel.NIGHTLY:

}
return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
}
export function resolveDownloadPath(platform, buildId) {
const [channel, resolvedBuildId] = parseBuildId(buildId);
switch (channel) {
case FirefoxChannel.NIGHTLY:
return `${baseUrl}/${resolveDownloadPath(platform, resolvedBuildId).join('/')}`;
return [archiveNightly(platform, resolvedBuildId)];
case FirefoxChannel.DEVEDITION:

@@ -81,8 +85,10 @@ case FirefoxChannel.BETA:

case FirefoxChannel.ESR:
return `${baseUrl}/${resolvedBuildId}/${platformName(platform)}/en-US/${archive(platform, resolvedBuildId)}`;
return [
resolvedBuildId,
platformName(platform),
'en-US',
archive(platform, resolvedBuildId),
];
}
}
export function resolveDownloadPath(platform, buildId) {
return [archiveNightly(platform, buildId)];
}
export function relativeExecutablePath(platform, buildId) {

@@ -89,0 +95,0 @@ const [channel] = parseBuildId(buildId);

@@ -109,2 +109,7 @@ /**

}
yargs.option('install-deps', {
type: 'boolean',
desc: 'Whether to attempt installing system dependencies (only supported on Linux, requires root privileges).',
default: false,
});
yargs.example('$0 install chrome', `Install the ${latestOrPinned} available build of the Chrome browser.`);

@@ -259,2 +264,3 @@ yargs.example('$0 install chrome@latest', 'Install the latest available build for the Chrome browser.');

buildIdAlias: originalBuildId !== args.browser.buildId ? originalBuildId : undefined,
installDeps: args.installDeps,
});

@@ -261,0 +267,0 @@ console.log(`${args.browser.name}@${args.browser.buildId} ${computeExecutablePath({

@@ -63,4 +63,19 @@ /**

forceFallbackForTesting?: boolean;
/**
* Whether to attempt to install system-level dependencies required
* for the browser.
*
* Only supported for Chrome on Debian or Ubuntu.
* Requires system-level privileges to run `apt-get`.
*
* @defaultValue `false`
*/
installDeps?: boolean;
}
/**
* Downloads and unpacks the browser archive according to the
* {@link InstallOptions}.
*
* @returns a {@link InstalledBrowser} instance.
*
* @public

@@ -72,2 +87,7 @@ */

/**
* Downloads the browser archive according to the {@link InstallOptions} without
* unpacking.
*
* @returns the absolute path to the archive.
*
* @public

@@ -74,0 +94,0 @@ */

@@ -8,3 +8,3 @@ /**

import { spawnSync } from 'child_process';
import { existsSync } from 'fs';
import { existsSync, readFileSync } from 'fs';
import { mkdir, unlink } from 'fs/promises';

@@ -87,2 +87,33 @@ import os from 'os';

}
async function installDeps(installedBrowser) {
if (process.platform !== 'linux' ||
installedBrowser.platform !== BrowserPlatform.LINUX) {
return;
}
// Currently, only Debian-like deps are supported.
const depsPath = path.join(path.dirname(installedBrowser.executablePath), 'deb.deps');
if (!existsSync(depsPath)) {
debugInstall(`deb.deps file was not found at ${depsPath}`);
return;
}
const data = readFileSync(depsPath, 'utf-8').split('\n').join(',');
if (process.getuid?.() !== 0) {
throw new Error('Installing system dependencies requires root privileges');
}
let result = spawnSync('apt-get', ['-v']);
if (result.status !== 0) {
throw new Error('Failed to install system dependencies: apt-get does not seem to be available');
}
debugInstall(`Trying to install dependencies: ${data}`);
result = spawnSync('apt-get', [
'satisfy',
'-y',
data,
'--no-install-recommends',
]);
if (result.status !== 0) {
throw new Error(`Failed to install system dependencies: status=${result.status},error=${result.error},stdout=${result.stdout.toString('utf8')},stderr=${result.stderr.toString('utf8')}`);
}
debugInstall(`Installed system dependencies ${data}`);
}
async function installUrl(url, options) {

@@ -119,2 +150,5 @@ options.platform ??= detectBrowserPlatform();

await runSetup(installedBrowser);
if (options.installDeps) {
await installDeps(installedBrowser);
}
return installedBrowser;

@@ -145,2 +179,5 @@ }

await runSetup(installedBrowser);
if (options.installDeps) {
await installDeps(installedBrowser);
}
return installedBrowser;

@@ -147,0 +184,0 @@ }

@@ -65,14 +65,64 @@ /**

export interface LaunchOptions {
/**
* Absolute path to the browser's executable.
*/
executablePath: string;
/**
* Configures stdio streams to open two additional streams for automation over
* those streams instead of WebSocket.
*
* @defaultValue `false`.
*/
pipe?: boolean;
/**
* If true, forwards the browser's process stdout and stderr to the Node's
* process stdout and stderr.
*
* @defaultValue `false`.
*/
dumpio?: boolean;
/**
* Additional arguments to pass to the executable when launching.
*/
args?: string[];
/**
* Environment variables to set for the browser process.
*/
env?: Record<string, string | undefined>;
/**
* Handles SIGINT in the Node process and tries to kill the browser process.
*
* @defaultValue `true`.
*/
handleSIGINT?: boolean;
/**
* Handles SIGTERM in the Node process and tries to gracefully close the browser
* process.
*
* @defaultValue `true`.
*/
handleSIGTERM?: boolean;
/**
* Handles SIGHUP in the Node process and tries to gracefully close the browser process.
*
* @defaultValue `true`.
*/
handleSIGHUP?: boolean;
/**
* Whether to spawn process in the {@link https://nodejs.org/api/child_process.html#optionsdetached | detached}
* mode.
*
* @defaultValue `true` except on Windows.
*/
detached?: boolean;
/**
* A callback to run after the browser process exits or before the process
* will be closed via the {@link Process.close} call (including when handling
* signals). The callback is only run once.
*/
onExit?: () => Promise<void>;
}
/**
* Launches a browser process according to {@link LaunchOptions}.
*
* @public

@@ -79,0 +129,0 @@ */

@@ -39,2 +39,4 @@ /**

/**
* Launches a browser process according to {@link LaunchOptions}.
*
* @public

@@ -41,0 +43,0 @@ */

{
"name": "@puppeteer/browsers",
"version": "2.3.1",
"version": "2.4.0",
"description": "Download and launch browsers",

@@ -112,4 +112,4 @@ "scripts": {

"@types/unbzip2-stream": "1.4.3",
"@types/yargs": "17.0.32"
"@types/yargs": "17.0.33"
}
}

@@ -69,3 +69,3 @@ /**

): string {
const [channel, resolvedBuildId] = parseBuildId(buildId);
const [channel] = parseBuildId(buildId);
switch (channel) {

@@ -85,5 +85,13 @@ case FirefoxChannel.NIGHTLY:

}
return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
}
export function resolveDownloadPath(
platform: BrowserPlatform,
buildId: string
): string[] {
const [channel, resolvedBuildId] = parseBuildId(buildId);
switch (channel) {
case FirefoxChannel.NIGHTLY:
return `${baseUrl}/${resolveDownloadPath(platform, resolvedBuildId).join('/')}`;
return [archiveNightly(platform, resolvedBuildId)];
case FirefoxChannel.DEVEDITION:

@@ -93,13 +101,11 @@ case FirefoxChannel.BETA:

case FirefoxChannel.ESR:
return `${baseUrl}/${resolvedBuildId}/${platformName(platform)}/en-US/${archive(platform, resolvedBuildId)}`;
return [
resolvedBuildId,
platformName(platform),
'en-US',
archive(platform, resolvedBuildId),
];
}
}
export function resolveDownloadPath(
platform: BrowserPlatform,
buildId: string
): string[] {
return [archiveNightly(platform, buildId)];
}
export function relativeExecutablePath(

@@ -106,0 +112,0 @@ platform: BrowserPlatform,

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

baseUrl?: string;
installDeps?: boolean;
}

@@ -184,2 +185,7 @@

}
yargs.option('install-deps', {
type: 'boolean',
desc: 'Whether to attempt installing system dependencies (only supported on Linux, requires root privileges).',
default: false,
});
yargs.example(

@@ -445,2 +451,3 @@ '$0 install chrome',

originalBuildId !== args.browser.buildId ? originalBuildId : undefined,
installDeps: args.installDeps,
});

@@ -447,0 +454,0 @@ console.log(

@@ -9,3 +9,3 @@ /**

import {spawnSync} from 'child_process';
import {existsSync} from 'fs';
import {existsSync, readFileSync} from 'fs';
import {mkdir, unlink} from 'fs/promises';

@@ -102,5 +102,21 @@ import os from 'os';

forceFallbackForTesting?: boolean;
/**
* Whether to attempt to install system-level dependencies required
* for the browser.
*
* Only supported for Chrome on Debian or Ubuntu.
* Requires system-level privileges to run `apt-get`.
*
* @defaultValue `false`
*/
installDeps?: boolean;
}
/**
* Downloads and unpacks the browser archive according to the
* {@link InstallOptions}.
*
* @returns a {@link InstalledBrowser} instance.
*
* @public

@@ -112,2 +128,7 @@ */

/**
* Downloads the browser archive according to the {@link InstallOptions} without
* unpacking.
*
* @returns the absolute path to the archive.
*
* @public

@@ -190,2 +211,43 @@ */

async function installDeps(installedBrowser: InstalledBrowser) {
if (
process.platform !== 'linux' ||
installedBrowser.platform !== BrowserPlatform.LINUX
) {
return;
}
// Currently, only Debian-like deps are supported.
const depsPath = path.join(
path.dirname(installedBrowser.executablePath),
'deb.deps'
);
if (!existsSync(depsPath)) {
debugInstall(`deb.deps file was not found at ${depsPath}`);
return;
}
const data = readFileSync(depsPath, 'utf-8').split('\n').join(',');
if (process.getuid?.() !== 0) {
throw new Error('Installing system dependencies requires root privileges');
}
let result = spawnSync('apt-get', ['-v']);
if (result.status !== 0) {
throw new Error(
'Failed to install system dependencies: apt-get does not seem to be available'
);
}
debugInstall(`Trying to install dependencies: ${data}`);
result = spawnSync('apt-get', [
'satisfy',
'-y',
data,
'--no-install-recommends',
]);
if (result.status !== 0) {
throw new Error(
`Failed to install system dependencies: status=${result.status},error=${result.error},stdout=${result.stdout.toString('utf8')},stderr=${result.stderr.toString('utf8')}`
);
}
debugInstall(`Installed system dependencies ${data}`);
}
async function installUrl(

@@ -241,2 +303,5 @@ url: URL,

await runSetup(installedBrowser);
if (options.installDeps) {
await installDeps(installedBrowser);
}
return installedBrowser;

@@ -273,2 +338,5 @@ }

await runSetup(installedBrowser);
if (options.installDeps) {
await installDeps(installedBrowser);
}
return installedBrowser;

@@ -275,0 +343,0 @@ } finally {

@@ -107,11 +107,59 @@ /**

export interface LaunchOptions {
/**
* Absolute path to the browser's executable.
*/
executablePath: string;
/**
* Configures stdio streams to open two additional streams for automation over
* those streams instead of WebSocket.
*
* @defaultValue `false`.
*/
pipe?: boolean;
/**
* If true, forwards the browser's process stdout and stderr to the Node's
* process stdout and stderr.
*
* @defaultValue `false`.
*/
dumpio?: boolean;
/**
* Additional arguments to pass to the executable when launching.
*/
args?: string[];
/**
* Environment variables to set for the browser process.
*/
env?: Record<string, string | undefined>;
/**
* Handles SIGINT in the Node process and tries to kill the browser process.
*
* @defaultValue `true`.
*/
handleSIGINT?: boolean;
/**
* Handles SIGTERM in the Node process and tries to gracefully close the browser
* process.
*
* @defaultValue `true`.
*/
handleSIGTERM?: boolean;
/**
* Handles SIGHUP in the Node process and tries to gracefully close the browser process.
*
* @defaultValue `true`.
*/
handleSIGHUP?: boolean;
/**
* Whether to spawn process in the {@link https://nodejs.org/api/child_process.html#optionsdetached | detached}
* mode.
*
* @defaultValue `true` except on Windows.
*/
detached?: boolean;
/**
* A callback to run after the browser process exits or before the process
* will be closed via the {@link Process.close} call (including when handling
* signals). The callback is only run once.
*/
onExit?: () => Promise<void>;

@@ -121,2 +169,4 @@ }

/**
* Launches a browser process according to {@link LaunchOptions}.
*
* @public

@@ -123,0 +173,0 @@ */

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc