@puppeteer/browsers
Advanced tools
Comparing version 2.2.4 to 2.3.0
@@ -23,3 +23,6 @@ /** | ||
pinnedBrowsers?: Partial<{ | ||
[key in Browser]: string; | ||
[key in Browser]: { | ||
buildId: string; | ||
skipDownload: boolean; | ||
}; | ||
}>; | ||
@@ -26,0 +29,0 @@ }, rl?: readline.Interface); |
@@ -124,4 +124,6 @@ "use strict"; | ||
const latestOrPinned = this.#pinnedBrowsers ? 'pinned' : 'latest'; | ||
// If there are pinned browsers allow the positional arg to be optional | ||
const browserArgType = this.#pinnedBrowsers ? '[browser]' : '<browser>'; | ||
return yargs | ||
.command('install <browser>', 'Download and install the specified browser. If successful, the command outputs the actual browser buildId that was installed and the absolute path to the browser executable (format: <browser>@<buildID> <path>).', yargs => { | ||
.command(`install ${browserArgType}`, 'Download and install the specified browser. If successful, the command outputs the actual browser buildId that was installed and the absolute path to the browser executable (format: <browser>@<buildID> <path>).', yargs => { | ||
this.#defineBrowserParameter(yargs); | ||
@@ -134,2 +136,5 @@ this.#definePlatformParameter(yargs); | ||
}); | ||
if (this.#pinnedBrowsers) { | ||
yargs.example('$0 install', 'Install all pinned browsers'); | ||
} | ||
yargs.example('$0 install chrome', `Install the ${latestOrPinned} available build of the Chrome browser.`); | ||
@@ -162,32 +167,27 @@ yargs.example('$0 install chrome@latest', 'Install the latest available build for the Chrome browser.'); | ||
const args = argv; | ||
args.platform ??= (0, detectPlatform_js_1.detectBrowserPlatform)(); | ||
if (!args.platform) { | ||
throw new Error(`Could not resolve the current platform`); | ||
} | ||
if (args.browser.buildId === 'pinned') { | ||
const pinnedVersion = this.#pinnedBrowsers?.[args.browser.name]; | ||
if (!pinnedVersion) { | ||
throw new Error(`No pinned version found for ${args.browser.name}`); | ||
if (this.#pinnedBrowsers && !args.browser) { | ||
// Use allSettled to avoid scenarios that | ||
// a browser may fail early and leave the other | ||
// installation in a faulty state | ||
const result = await Promise.allSettled(Object.entries(this.#pinnedBrowsers).map(async ([browser, options]) => { | ||
if (options.skipDownload) { | ||
return; | ||
} | ||
await this.#install({ | ||
...argv, | ||
browser: { | ||
name: browser, | ||
buildId: options.buildId, | ||
}, | ||
}); | ||
})); | ||
for (const install of result) { | ||
if (install.status === 'rejected') { | ||
throw install.reason; | ||
} | ||
} | ||
args.browser.buildId = pinnedVersion; | ||
} | ||
const originalBuildId = args.browser.buildId; | ||
args.browser.buildId = await (0, browser_data_js_1.resolveBuildId)(args.browser.name, args.platform, args.browser.buildId); | ||
await (0, install_js_1.install)({ | ||
browser: args.browser.name, | ||
buildId: args.browser.buildId, | ||
platform: args.platform, | ||
cacheDir: args.path ?? this.#cachePath, | ||
downloadProgressCallback: makeProgressCallback(args.browser.name, args.browser.buildId), | ||
baseUrl: args.baseUrl, | ||
buildIdAlias: originalBuildId !== args.browser.buildId | ||
? originalBuildId | ||
: undefined, | ||
}); | ||
console.log(`${args.browser.name}@${args.browser.buildId} ${(0, launch_js_1.computeExecutablePath)({ | ||
browser: args.browser.name, | ||
buildId: args.browser.buildId, | ||
cacheDir: args.path ?? this.#cachePath, | ||
platform: args.platform, | ||
})}`); | ||
else { | ||
await this.#install(args); | ||
} | ||
}) | ||
@@ -265,2 +265,35 @@ .command('launch <browser>', 'Launch the specified browser', yargs => { | ||
} | ||
async #install(args) { | ||
args.platform ??= (0, detectPlatform_js_1.detectBrowserPlatform)(); | ||
if (!args.browser) { | ||
throw new Error(`No browser arg proveded`); | ||
} | ||
if (!args.platform) { | ||
throw new Error(`Could not resolve the current platform`); | ||
} | ||
if (args.browser.buildId === 'pinned') { | ||
const options = this.#pinnedBrowsers?.[args.browser.name]; | ||
if (!options || !options.buildId) { | ||
throw new Error(`No pinned version found for ${args.browser.name}`); | ||
} | ||
args.browser.buildId = options.buildId; | ||
} | ||
const originalBuildId = args.browser.buildId; | ||
args.browser.buildId = await (0, browser_data_js_1.resolveBuildId)(args.browser.name, args.platform, args.browser.buildId); | ||
await (0, install_js_1.install)({ | ||
browser: args.browser.name, | ||
buildId: args.browser.buildId, | ||
platform: args.platform, | ||
cacheDir: args.path ?? this.#cachePath, | ||
downloadProgressCallback: makeProgressCallback(args.browser.name, args.browser.buildId), | ||
baseUrl: args.baseUrl, | ||
buildIdAlias: originalBuildId !== args.browser.buildId ? originalBuildId : undefined, | ||
}); | ||
console.log(`${args.browser.name}@${args.browser.buildId} ${(0, launch_js_1.computeExecutablePath)({ | ||
browser: args.browser.name, | ||
buildId: args.browser.buildId, | ||
cacheDir: args.path ?? this.#cachePath, | ||
platform: args.platform, | ||
})}`); | ||
} | ||
} | ||
@@ -267,0 +300,0 @@ exports.CLI = CLI; |
@@ -13,2 +13,3 @@ "use strict"; | ||
const assert_1 = __importDefault(require("assert")); | ||
const child_process_1 = require("child_process"); | ||
const fs_1 = require("fs"); | ||
@@ -123,2 +124,3 @@ const promises_1 = require("fs/promises"); | ||
} | ||
await runSetup(installedBrowser); | ||
return installedBrowser; | ||
@@ -148,2 +150,3 @@ } | ||
} | ||
await runSetup(installedBrowser); | ||
return installedBrowser; | ||
@@ -157,2 +160,26 @@ } | ||
} | ||
async function runSetup(installedBrowser) { | ||
// On Windows for Chrome invoke setup.exe to configure sandboxes. | ||
if ((installedBrowser.platform === browser_data_js_1.BrowserPlatform.WIN32 || | ||
installedBrowser.platform === browser_data_js_1.BrowserPlatform.WIN64) && | ||
installedBrowser.browser === browser_data_js_1.Browser.CHROME && | ||
installedBrowser.platform === (0, detectPlatform_js_1.detectBrowserPlatform)()) { | ||
try { | ||
debugTime('permissions'); | ||
const browserDir = path_1.default.dirname(installedBrowser.executablePath); | ||
const setupExePath = path_1.default.join(browserDir, 'setup.exe'); | ||
if (!(0, fs_1.existsSync)(setupExePath)) { | ||
return; | ||
} | ||
(0, child_process_1.spawnSync)(path_1.default.join(browserDir, 'setup.exe'), [`--configure-browser-in-directory=` + browserDir], { | ||
shell: true, | ||
}); | ||
// TODO: Handle error here. Currently the setup.exe sometimes | ||
// errors although it sets the permissions correctly. | ||
} | ||
finally { | ||
debugTimeEnd('permissions'); | ||
} | ||
} | ||
} | ||
/** | ||
@@ -159,0 +186,0 @@ * |
@@ -23,3 +23,6 @@ /** | ||
pinnedBrowsers?: Partial<{ | ||
[key in Browser]: string; | ||
[key in Browser]: { | ||
buildId: string; | ||
skipDownload: boolean; | ||
}; | ||
}>; | ||
@@ -26,0 +29,0 @@ }, rl?: readline.Interface); |
@@ -95,4 +95,6 @@ /** | ||
const latestOrPinned = this.#pinnedBrowsers ? 'pinned' : 'latest'; | ||
// If there are pinned browsers allow the positional arg to be optional | ||
const browserArgType = this.#pinnedBrowsers ? '[browser]' : '<browser>'; | ||
return yargs | ||
.command('install <browser>', 'Download and install the specified browser. If successful, the command outputs the actual browser buildId that was installed and the absolute path to the browser executable (format: <browser>@<buildID> <path>).', yargs => { | ||
.command(`install ${browserArgType}`, 'Download and install the specified browser. If successful, the command outputs the actual browser buildId that was installed and the absolute path to the browser executable (format: <browser>@<buildID> <path>).', yargs => { | ||
this.#defineBrowserParameter(yargs); | ||
@@ -105,2 +107,5 @@ this.#definePlatformParameter(yargs); | ||
}); | ||
if (this.#pinnedBrowsers) { | ||
yargs.example('$0 install', 'Install all pinned browsers'); | ||
} | ||
yargs.example('$0 install chrome', `Install the ${latestOrPinned} available build of the Chrome browser.`); | ||
@@ -133,32 +138,27 @@ yargs.example('$0 install chrome@latest', 'Install the latest available build for the Chrome browser.'); | ||
const args = argv; | ||
args.platform ??= detectBrowserPlatform(); | ||
if (!args.platform) { | ||
throw new Error(`Could not resolve the current platform`); | ||
} | ||
if (args.browser.buildId === 'pinned') { | ||
const pinnedVersion = this.#pinnedBrowsers?.[args.browser.name]; | ||
if (!pinnedVersion) { | ||
throw new Error(`No pinned version found for ${args.browser.name}`); | ||
if (this.#pinnedBrowsers && !args.browser) { | ||
// Use allSettled to avoid scenarios that | ||
// a browser may fail early and leave the other | ||
// installation in a faulty state | ||
const result = await Promise.allSettled(Object.entries(this.#pinnedBrowsers).map(async ([browser, options]) => { | ||
if (options.skipDownload) { | ||
return; | ||
} | ||
await this.#install({ | ||
...argv, | ||
browser: { | ||
name: browser, | ||
buildId: options.buildId, | ||
}, | ||
}); | ||
})); | ||
for (const install of result) { | ||
if (install.status === 'rejected') { | ||
throw install.reason; | ||
} | ||
} | ||
args.browser.buildId = pinnedVersion; | ||
} | ||
const originalBuildId = args.browser.buildId; | ||
args.browser.buildId = await resolveBuildId(args.browser.name, args.platform, args.browser.buildId); | ||
await install({ | ||
browser: args.browser.name, | ||
buildId: args.browser.buildId, | ||
platform: args.platform, | ||
cacheDir: args.path ?? this.#cachePath, | ||
downloadProgressCallback: makeProgressCallback(args.browser.name, args.browser.buildId), | ||
baseUrl: args.baseUrl, | ||
buildIdAlias: originalBuildId !== args.browser.buildId | ||
? originalBuildId | ||
: undefined, | ||
}); | ||
console.log(`${args.browser.name}@${args.browser.buildId} ${computeExecutablePath({ | ||
browser: args.browser.name, | ||
buildId: args.browser.buildId, | ||
cacheDir: args.path ?? this.#cachePath, | ||
platform: args.platform, | ||
})}`); | ||
else { | ||
await this.#install(args); | ||
} | ||
}) | ||
@@ -236,2 +236,35 @@ .command('launch <browser>', 'Launch the specified browser', yargs => { | ||
} | ||
async #install(args) { | ||
args.platform ??= detectBrowserPlatform(); | ||
if (!args.browser) { | ||
throw new Error(`No browser arg proveded`); | ||
} | ||
if (!args.platform) { | ||
throw new Error(`Could not resolve the current platform`); | ||
} | ||
if (args.browser.buildId === 'pinned') { | ||
const options = this.#pinnedBrowsers?.[args.browser.name]; | ||
if (!options || !options.buildId) { | ||
throw new Error(`No pinned version found for ${args.browser.name}`); | ||
} | ||
args.browser.buildId = options.buildId; | ||
} | ||
const originalBuildId = args.browser.buildId; | ||
args.browser.buildId = await resolveBuildId(args.browser.name, args.platform, args.browser.buildId); | ||
await install({ | ||
browser: args.browser.name, | ||
buildId: args.browser.buildId, | ||
platform: args.platform, | ||
cacheDir: args.path ?? this.#cachePath, | ||
downloadProgressCallback: makeProgressCallback(args.browser.name, args.browser.buildId), | ||
baseUrl: args.baseUrl, | ||
buildIdAlias: originalBuildId !== args.browser.buildId ? originalBuildId : undefined, | ||
}); | ||
console.log(`${args.browser.name}@${args.browser.buildId} ${computeExecutablePath({ | ||
browser: args.browser.name, | ||
buildId: args.browser.buildId, | ||
cacheDir: args.path ?? this.#cachePath, | ||
platform: args.platform, | ||
})}`); | ||
} | ||
} | ||
@@ -238,0 +271,0 @@ /** |
@@ -7,2 +7,3 @@ /** | ||
import assert from 'assert'; | ||
import { spawnSync } from 'child_process'; | ||
import { existsSync } from 'fs'; | ||
@@ -116,2 +117,3 @@ import { mkdir, unlink } from 'fs/promises'; | ||
} | ||
await runSetup(installedBrowser); | ||
return installedBrowser; | ||
@@ -141,2 +143,3 @@ } | ||
} | ||
await runSetup(installedBrowser); | ||
return installedBrowser; | ||
@@ -150,2 +153,26 @@ } | ||
} | ||
async function runSetup(installedBrowser) { | ||
// On Windows for Chrome invoke setup.exe to configure sandboxes. | ||
if ((installedBrowser.platform === BrowserPlatform.WIN32 || | ||
installedBrowser.platform === BrowserPlatform.WIN64) && | ||
installedBrowser.browser === Browser.CHROME && | ||
installedBrowser.platform === detectBrowserPlatform()) { | ||
try { | ||
debugTime('permissions'); | ||
const browserDir = path.dirname(installedBrowser.executablePath); | ||
const setupExePath = path.join(browserDir, 'setup.exe'); | ||
if (!existsSync(setupExePath)) { | ||
return; | ||
} | ||
spawnSync(path.join(browserDir, 'setup.exe'), [`--configure-browser-in-directory=` + browserDir], { | ||
shell: true, | ||
}); | ||
// TODO: Handle error here. Currently the setup.exe sometimes | ||
// errors although it sets the permissions correctly. | ||
} | ||
finally { | ||
debugTimeEnd('permissions'); | ||
} | ||
} | ||
} | ||
/** | ||
@@ -152,0 +179,0 @@ * |
{ | ||
"name": "@puppeteer/browsers", | ||
"version": "2.2.4", | ||
"version": "2.3.0", | ||
"description": "Download and launch browsers", | ||
@@ -105,3 +105,3 @@ "scripts": { | ||
"yargs": "^17.7.2", | ||
"semver": "^7.6.2" | ||
"semver": "^7.6.3" | ||
}, | ||
@@ -108,0 +108,0 @@ "devDependencies": { |
143
src/CLI.ts
@@ -30,7 +30,8 @@ /** | ||
interface InstallBrowser { | ||
name: Browser; | ||
buildId: string; | ||
} | ||
interface InstallArgs { | ||
browser: { | ||
name: Browser; | ||
buildId: string; | ||
}; | ||
browser?: InstallBrowser; | ||
path?: string; | ||
@@ -64,3 +65,8 @@ platform?: BrowserPlatform; | ||
#allowCachePathOverride = true; | ||
#pinnedBrowsers?: Partial<{[key in Browser]: string}>; | ||
#pinnedBrowsers?: Partial<{ | ||
[key in Browser]: { | ||
buildId: string; | ||
skipDownload: boolean; | ||
}; | ||
}>; | ||
#prefixCommand?: {cmd: string; description: string}; | ||
@@ -76,3 +82,8 @@ | ||
allowCachePathOverride?: boolean; | ||
pinnedBrowsers?: Partial<{[key in Browser]: string}>; | ||
pinnedBrowsers?: Partial<{ | ||
[key in Browser]: { | ||
buildId: string; | ||
skipDownload: boolean; | ||
}; | ||
}>; | ||
}, | ||
@@ -158,5 +169,7 @@ rl?: readline.Interface | ||
const latestOrPinned = this.#pinnedBrowsers ? 'pinned' : 'latest'; | ||
// If there are pinned browsers allow the positional arg to be optional | ||
const browserArgType = this.#pinnedBrowsers ? '[browser]' : '<browser>'; | ||
return yargs | ||
.command( | ||
'install <browser>', | ||
`install ${browserArgType}`, | ||
'Download and install the specified browser. If successful, the command outputs the actual browser buildId that was installed and the absolute path to the browser executable (format: <browser>@<buildID> <path>).', | ||
@@ -171,2 +184,5 @@ yargs => { | ||
}); | ||
if (this.#pinnedBrowsers) { | ||
yargs.example('$0 install', 'Install all pinned browsers'); | ||
} | ||
yargs.example( | ||
@@ -269,46 +285,31 @@ '$0 install chrome', | ||
const args = argv as unknown as InstallArgs; | ||
args.platform ??= detectBrowserPlatform(); | ||
if (!args.platform) { | ||
throw new Error(`Could not resolve the current platform`); | ||
} | ||
if (args.browser.buildId === 'pinned') { | ||
const pinnedVersion = this.#pinnedBrowsers?.[args.browser.name]; | ||
if (!pinnedVersion) { | ||
throw new Error( | ||
`No pinned version found for ${args.browser.name}` | ||
); | ||
if (this.#pinnedBrowsers && !args.browser) { | ||
// Use allSettled to avoid scenarios that | ||
// a browser may fail early and leave the other | ||
// installation in a faulty state | ||
const result = await Promise.allSettled( | ||
Object.entries(this.#pinnedBrowsers).map( | ||
async ([browser, options]) => { | ||
if (options.skipDownload) { | ||
return; | ||
} | ||
await this.#install({ | ||
...argv, | ||
browser: { | ||
name: browser as Browser, | ||
buildId: options.buildId, | ||
}, | ||
}); | ||
} | ||
) | ||
); | ||
for (const install of result) { | ||
if (install.status === 'rejected') { | ||
throw install.reason; | ||
} | ||
} | ||
args.browser.buildId = pinnedVersion; | ||
} else { | ||
await this.#install(args); | ||
} | ||
const originalBuildId = args.browser.buildId; | ||
args.browser.buildId = await resolveBuildId( | ||
args.browser.name, | ||
args.platform, | ||
args.browser.buildId | ||
); | ||
await install({ | ||
browser: args.browser.name, | ||
buildId: args.browser.buildId, | ||
platform: args.platform, | ||
cacheDir: args.path ?? this.#cachePath, | ||
downloadProgressCallback: makeProgressCallback( | ||
args.browser.name, | ||
args.browser.buildId | ||
), | ||
baseUrl: args.baseUrl, | ||
buildIdAlias: | ||
originalBuildId !== args.browser.buildId | ||
? originalBuildId | ||
: undefined, | ||
}); | ||
console.log( | ||
`${args.browser.name}@${ | ||
args.browser.buildId | ||
} ${computeExecutablePath({ | ||
browser: args.browser.name, | ||
buildId: args.browser.buildId, | ||
cacheDir: args.path ?? this.#cachePath, | ||
platform: args.platform, | ||
})}` | ||
); | ||
} | ||
@@ -414,2 +415,46 @@ ) | ||
} | ||
async #install(args: InstallArgs) { | ||
args.platform ??= detectBrowserPlatform(); | ||
if (!args.browser) { | ||
throw new Error(`No browser arg proveded`); | ||
} | ||
if (!args.platform) { | ||
throw new Error(`Could not resolve the current platform`); | ||
} | ||
if (args.browser.buildId === 'pinned') { | ||
const options = this.#pinnedBrowsers?.[args.browser.name]; | ||
if (!options || !options.buildId) { | ||
throw new Error(`No pinned version found for ${args.browser.name}`); | ||
} | ||
args.browser.buildId = options.buildId; | ||
} | ||
const originalBuildId = args.browser.buildId; | ||
args.browser.buildId = await resolveBuildId( | ||
args.browser.name, | ||
args.platform, | ||
args.browser.buildId | ||
); | ||
await install({ | ||
browser: args.browser.name, | ||
buildId: args.browser.buildId, | ||
platform: args.platform, | ||
cacheDir: args.path ?? this.#cachePath, | ||
downloadProgressCallback: makeProgressCallback( | ||
args.browser.name, | ||
args.browser.buildId | ||
), | ||
baseUrl: args.baseUrl, | ||
buildIdAlias: | ||
originalBuildId !== args.browser.buildId ? originalBuildId : undefined, | ||
}); | ||
console.log( | ||
`${args.browser.name}@${args.browser.buildId} ${computeExecutablePath({ | ||
browser: args.browser.name, | ||
buildId: args.browser.buildId, | ||
cacheDir: args.path ?? this.#cachePath, | ||
platform: args.platform, | ||
})}` | ||
); | ||
} | ||
} | ||
@@ -416,0 +461,0 @@ |
@@ -8,2 +8,3 @@ /** | ||
import assert from 'assert'; | ||
import {spawnSync} from 'child_process'; | ||
import {existsSync} from 'fs'; | ||
@@ -236,2 +237,3 @@ import {mkdir, unlink} from 'fs/promises'; | ||
} | ||
await runSetup(installedBrowser); | ||
return installedBrowser; | ||
@@ -254,2 +256,3 @@ } | ||
} | ||
const installedBrowser = new InstalledBrowser( | ||
@@ -266,2 +269,4 @@ cache, | ||
} | ||
await runSetup(installedBrowser); | ||
return installedBrowser; | ||
@@ -275,2 +280,32 @@ } finally { | ||
async function runSetup(installedBrowser: InstalledBrowser): Promise<void> { | ||
// On Windows for Chrome invoke setup.exe to configure sandboxes. | ||
if ( | ||
(installedBrowser.platform === BrowserPlatform.WIN32 || | ||
installedBrowser.platform === BrowserPlatform.WIN64) && | ||
installedBrowser.browser === Browser.CHROME && | ||
installedBrowser.platform === detectBrowserPlatform() | ||
) { | ||
try { | ||
debugTime('permissions'); | ||
const browserDir = path.dirname(installedBrowser.executablePath); | ||
const setupExePath = path.join(browserDir, 'setup.exe'); | ||
if (!existsSync(setupExePath)) { | ||
return; | ||
} | ||
spawnSync( | ||
path.join(browserDir, 'setup.exe'), | ||
[`--configure-browser-in-directory=` + browserDir], | ||
{ | ||
shell: true, | ||
} | ||
); | ||
// TODO: Handle error here. Currently the setup.exe sometimes | ||
// errors although it sets the permissions correctly. | ||
} finally { | ||
debugTimeEnd('permissions'); | ||
} | ||
} | ||
} | ||
/** | ||
@@ -277,0 +312,0 @@ * @public |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
487700
8868
10
Updatedsemver@^7.6.3