Skip to content

🎥 Make videos programmatically with React

browser fetcher

Jonny Burgerd9a60a52b5a8
diff --git a/packages/renderer/src/browser/BrowserFetcher.ts b/packages/renderer/src/browser/BrowserFetcher.ts
index 19f172d089..eb0c51919b 100644
--- a/packages/renderer/src/browser/BrowserFetcher.ts
+++ b/packages/renderer/src/browser/BrowserFetcher.ts
@@ -200,12 +200,7 @@ export const download = async (
const archivePath = path.join(downloadsFolder, fileName);
const outputPath = getFolderPath(revision, downloadsFolder, platform);
if (await existsAsync(outputPath)) {
- return getRevisionInfo(
- revision,
- product,
- getFolderPath(revision, downloadsFolder, platform),
- platform
- );
+ return getRevisionInfo(revision, product);
}
if (!(await existsAsync(downloadsFolder))) {
@@ -229,12 +224,7 @@ export const download = async (
}
}
- const revisionInfo = getRevisionInfo(
- revision,
- product,
- getFolderPath(revision, downloadsFolder, platform),
- platform
- );
+ const revisionInfo = getRevisionInfo(revision, product);
if (revisionInfo) {
await chmodAsync(revisionInfo.executablePath, 0o755);
}
@@ -289,11 +279,12 @@ export const getFolderPath = (
export const getRevisionInfo = (
revision: string,
- product: Product,
- folderPath: string,
- platform: Platform
+ product: Product
): BrowserFetcherRevisionInfo => {
let executablePath = '';
+ const downloadsFolder = getDownloadsFolder(product);
+ const platform = getPlatform(product);
+ const folderPath = getFolderPath(revision, downloadsFolder, platform);
if (product === 'chrome') {
if (platform === 'mac' || platform === 'mac_arm') {
executablePath = path.join(
diff --git a/packages/renderer/src/browser/Launcher.ts b/packages/renderer/src/browser/Launcher.ts
index cb51fcc1fc..05698ca6a4 100644
--- a/packages/renderer/src/browser/Launcher.ts
+++ b/packages/renderer/src/browser/Launcher.ts
@@ -23,12 +23,7 @@ import {BrowserRunner} from './BrowserRunner';
import type {PuppeteerNodeLaunchOptions} from './LaunchOptions';
-import {
- getDownloadsFolder,
- getFolderPath,
- getPlatform,
- getRevisionInfo,
-} from './BrowserFetcher';
+import {getRevisionInfo} from './BrowserFetcher';
import type {Product} from './Product';
const tmpDir = () => {
@@ -154,16 +149,7 @@ function resolveExecutablePath(launcher: ChromeLauncher): {
} {
const {product, _preferredRevision} = launcher;
- const revisionInfo = getRevisionInfo(
- _preferredRevision,
- 'chrome',
- getFolderPath(
- _preferredRevision,
- getDownloadsFolder(product),
- getPlatform(product)
- ),
- getPlatform(product)
- );
+ const revisionInfo = getRevisionInfo(_preferredRevision, 'chrome');
const firefoxHelp = `Run \`PUPPETEER_PRODUCT=firefox npm install\` to download a supported Firefox browser binary.`;
const chromeHelp = `Run \`npm install\` to download the correct Chromium revision (${launcher._preferredRevision}).`;
diff --git a/packages/renderer/src/browser/create-browser-fetcher.ts b/packages/renderer/src/browser/create-browser-fetcher.ts
index b9ab8583a3..a99bdc0f68 100644
--- a/packages/renderer/src/browser/create-browser-fetcher.ts
+++ b/packages/renderer/src/browser/create-browser-fetcher.ts
@@ -45,16 +45,7 @@ export async function downloadBrowser(product: Product): Promise<void> {
await fetchBinary(revision);
function fetchBinary(_revision: string) {
- const revisionInfo = getRevisionInfo(
- _revision,
- product,
- getFolderPath(
- _revision,
- getDownloadsFolder(product),
- getPlatform(product)
- ),
- getPlatform(product)
- );
+ const revisionInfo = getRevisionInfo(_revision, product);
// Do nothing if the revision is already downloaded.
if (revisionInfo.local) {
@@ -64,14 +55,14 @@ export async function downloadBrowser(product: Product): Promise<void> {
return;
}
- function onSuccess(localRevisions: string[]): void {
+ function onSuccess(_localRevisions: string[]): void {
console.log(
`${supportedProducts[product]} (${revisionInfo.revision}) downloaded to ${revisionInfo.folderPath}`
);
- localRevisions = localRevisions.filter((__revision) => {
+ _localRevisions = _localRevisions.filter((__revision) => {
return __revision !== revisionInfo.revision;
});
- const cleanupOldVersions = localRevisions.map((__revision) => {
+ const cleanupOldVersions = _localRevisions.map((__revision) => {
return removeBrowser(
__revision,
getFolderPath(
diff --git a/packages/renderer/src/get-local-browser-executable.ts b/packages/renderer/src/get-local-browser-executable.ts
index 6aa3edaf9d..dc207712f9 100644
--- a/packages/renderer/src/get-local-browser-executable.ts
+++ b/packages/renderer/src/get-local-browser-executable.ts
@@ -1,12 +1,7 @@
import fs from 'fs';
import type {Browser} from './browser';
import type {BrowserExecutable} from './browser-executable';
-import {
- getDownloadsFolder,
- getFolderPath,
- getPlatform,
- getRevisionInfo,
-} from './browser/BrowserFetcher';
+import {getRevisionInfo} from './browser/BrowserFetcher';
import {downloadBrowser} from './browser/create-browser-fetcher';
import type {Product} from './browser/Product';
import {PUPPETEER_REVISIONS} from './browser/revisions';
@@ -52,23 +47,6 @@ const getLocalBrowser = (product: Product) => {
return null;
};
-const getBrowserRevision = (product: Product) => {
- const platform = getPlatform(product);
-
- const revisionInfo = getRevisionInfo(
- PUPPETEER_REVISIONS.chromium,
- product,
- getFolderPath(
- PUPPETEER_REVISIONS.chromium,
- getDownloadsFolder(product),
- platform
- ),
- platform
- );
-
- return revisionInfo;
-};
-
type BrowserStatus =
| {
type: 'user-defined-path';
@@ -105,7 +83,7 @@ const getBrowserStatus = (
return {path: localBrowser, type: 'local-browser'};
}
- const revision = getBrowserRevision(product);
+ const revision = getRevisionInfo(PUPPETEER_REVISIONS.chromium, product);
if (revision.local !== null && fs.existsSync(revision.executablePath)) {
return {path: revision.executablePath, type: 'local-puppeteer-browser'};
}