@remotion/renderer 4.0.16 → 4.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/assets/get-video-stream-duration.d.ts +9 -0
  2. package/dist/assets/get-video-stream-duration.js +71 -0
  3. package/dist/browser/BrowserFetcher.d.ts +2 -19
  4. package/dist/browser/BrowserFetcher.js +73 -263
  5. package/dist/browser/LaunchOptions.d.ts +0 -2
  6. package/dist/browser/Launcher.d.ts +0 -5
  7. package/dist/browser/Launcher.js +5 -14
  8. package/dist/browser/PuppeteerNode.d.ts +1 -8
  9. package/dist/browser/PuppeteerNode.js +10 -27
  10. package/dist/browser/node.js +1 -5
  11. package/dist/browser.d.ts +1 -1
  12. package/dist/calculate-sar-dar-pixels.d.ts +9 -0
  13. package/dist/calculate-sar-dar-pixels.js +19 -0
  14. package/dist/client.d.ts +48 -48
  15. package/dist/compositor/payloads.d.ts +18 -0
  16. package/dist/determine-resize-params.d.ts +4 -0
  17. package/dist/determine-resize-params.js +10 -0
  18. package/dist/determine-vcodec-ffmpeg-flags.d.ts +2 -0
  19. package/dist/determine-vcodec-ffmpeg-flags.js +13 -0
  20. package/dist/ensure-ffmpeg.d.ts +18 -0
  21. package/dist/ensure-ffmpeg.js +58 -0
  22. package/dist/ensure-presentation-timestamp.d.ts +15 -0
  23. package/dist/ensure-presentation-timestamp.js +88 -0
  24. package/dist/extract-frame-from-video.d.ts +16 -0
  25. package/dist/extract-frame-from-video.js +191 -0
  26. package/dist/ffmpeg-executable.d.ts +1 -0
  27. package/dist/ffmpeg-executable.js +2 -0
  28. package/dist/ffmpeg-flags.d.ts +31 -0
  29. package/dist/ffmpeg-flags.js +245 -0
  30. package/dist/frame-to-ffmpeg-timestamp.d.ts +1 -0
  31. package/dist/frame-to-ffmpeg-timestamp.js +8 -0
  32. package/dist/get-can-extract-frames-fast.d.ts +14 -0
  33. package/dist/get-can-extract-frames-fast.js +71 -0
  34. package/dist/get-extension-from-codec.d.ts +2 -2
  35. package/dist/get-frame-of-video-slow.d.ts +17 -0
  36. package/dist/get-frame-of-video-slow.js +72 -0
  37. package/dist/get-local-browser-executable.d.ts +2 -3
  38. package/dist/get-local-browser-executable.js +45 -53
  39. package/dist/get-silent-parts.d.ts +8 -0
  40. package/dist/get-silent-parts.js +56 -0
  41. package/dist/get-video-info.d.ts +8 -0
  42. package/dist/get-video-info.js +59 -0
  43. package/dist/index.d.ts +45 -42
  44. package/dist/index.js +4 -1
  45. package/dist/is-beyond-last-frame.d.ts +3 -0
  46. package/dist/is-beyond-last-frame.js +12 -0
  47. package/dist/last-frame-from-video-cache.d.ts +17 -0
  48. package/dist/last-frame-from-video-cache.js +55 -0
  49. package/dist/legacy-webpack-config.d.ts +9 -0
  50. package/dist/legacy-webpack-config.js +13 -0
  51. package/dist/open-browser.js +3 -3
  52. package/dist/quality.d.ts +1 -0
  53. package/dist/quality.js +21 -0
  54. package/dist/render-media.js +5 -2
  55. package/dist/set-props-and-env.js +6 -3
  56. package/dist/stitch-frames-to-video.d.ts +1 -0
  57. package/dist/try-to-extract-frame-of-video-fast.d.ts +12 -0
  58. package/dist/try-to-extract-frame-of-video-fast.js +55 -0
  59. package/dist/validate-ffmpeg.d.ts +7 -0
  60. package/dist/validate-ffmpeg.js +77 -0
  61. package/dist/validate-opengl-renderer.d.ts +2 -3
  62. package/dist/validate-opengl-renderer.js +9 -4
  63. package/dist/validate-output-filename.d.ts +1 -1
  64. package/dist/warn-about-ffmpeg-version.d.ts +5 -0
  65. package/dist/warn-about-ffmpeg-version.js +37 -0
  66. package/package.json +9 -10
@@ -0,0 +1,9 @@
1
+ import type { FfmpegExecutable } from '../ffmpeg-executable';
2
+ import type { DownloadMap, VideoDurationResult } from './download-map';
3
+ export declare const parseVideoStreamDuration: (stdout: string) => VideoDurationResult;
4
+ export declare function getVideoStreamDurationwithoutCache({ src, ffprobeExecutable, remotionRoot, }: {
5
+ src: string;
6
+ ffprobeExecutable: FfmpegExecutable;
7
+ remotionRoot: string;
8
+ }): Promise<VideoDurationResult>;
9
+ export declare const getVideoStreamDuration: (downloadMap: DownloadMap, src: string, ffprobeExecutable: FfmpegExecutable, remotionRoot: string) => Promise<VideoDurationResult>;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getVideoStreamDuration = exports.getVideoStreamDurationwithoutCache = exports.parseVideoStreamDuration = void 0;
7
+ const execa_1 = __importDefault(require("execa"));
8
+ const ffmpeg_flags_1 = require("../ffmpeg-flags");
9
+ const p_limit_1 = require("../p-limit");
10
+ const limit = (0, p_limit_1.pLimit)(1);
11
+ const parseAlternativeDuration = (stdout) => {
12
+ const webmDuration = stdout.match(/TAG:DURATION=([0-9.]+):([0-9.]+):([0-9.]+)/);
13
+ if (!webmDuration) {
14
+ return null;
15
+ }
16
+ const [, hours, minutes, seconds] = webmDuration;
17
+ const hoursAsNumber = Number(hours);
18
+ if (Number.isNaN(hoursAsNumber)) {
19
+ return null;
20
+ }
21
+ const minutesAsNumber = Number(minutes);
22
+ if (Number.isNaN(minutesAsNumber)) {
23
+ return null;
24
+ }
25
+ const secondsAsNumber = Number(seconds);
26
+ if (Number.isNaN(secondsAsNumber)) {
27
+ return null;
28
+ }
29
+ return secondsAsNumber + minutesAsNumber * 60 + hoursAsNumber * 3600;
30
+ };
31
+ const parseVideoStreamDuration = (stdout) => {
32
+ const duration = stdout.match(/duration=([0-9.]+)/);
33
+ const alternativeDuration = parseAlternativeDuration(stdout);
34
+ const fps = stdout.match(/r_frame_rate=([0-9.]+)\/([0-9.]+)/);
35
+ const result = {
36
+ duration: duration ? parseFloat(duration[1]) : alternativeDuration,
37
+ fps: fps ? parseInt(fps[1], 10) / parseInt(fps[2], 10) : null,
38
+ };
39
+ return result;
40
+ };
41
+ exports.parseVideoStreamDuration = parseVideoStreamDuration;
42
+ async function getVideoStreamDurationwithoutCache({ src, ffprobeExecutable, remotionRoot, }) {
43
+ const args = [
44
+ ['-v', 'error'],
45
+ ['-select_streams', 'v:0'],
46
+ ['-show_entries', 'stream'],
47
+ [src],
48
+ ]
49
+ .reduce((acc, val) => acc.concat(val), [])
50
+ .filter(Boolean);
51
+ const task = await (0, execa_1.default)(await (0, ffmpeg_flags_1.getExecutableBinary)(ffprobeExecutable, remotionRoot, 'ffprobe'), args);
52
+ const result = (0, exports.parseVideoStreamDuration)(task.stdout);
53
+ return result;
54
+ }
55
+ exports.getVideoStreamDurationwithoutCache = getVideoStreamDurationwithoutCache;
56
+ async function getVideoStreamDurationUnlimited(downloadMap, src, ffprobeExecutable, remotionRoot) {
57
+ if (downloadMap.videoDurationResultCache[src]) {
58
+ return downloadMap.videoDurationResultCache[src];
59
+ }
60
+ const result = await getVideoStreamDurationwithoutCache({
61
+ src,
62
+ ffprobeExecutable,
63
+ remotionRoot,
64
+ });
65
+ downloadMap.videoDurationResultCache[src] = result;
66
+ return result;
67
+ }
68
+ const getVideoStreamDuration = (downloadMap, src, ffprobeExecutable, remotionRoot) => {
69
+ return limit(() => getVideoStreamDurationUnlimited(downloadMap, src, ffprobeExecutable, remotionRoot));
70
+ };
71
+ exports.getVideoStreamDuration = getVideoStreamDuration;
@@ -13,29 +13,12 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { Product } from './Product';
17
- type Platform = 'linux' | 'mac' | 'mac_arm' | 'win32' | 'win64';
18
16
  interface BrowserFetcherRevisionInfo {
19
17
  folderPath: string;
20
18
  executablePath: string;
21
19
  url: string;
22
20
  local: boolean;
23
- revision: string;
24
- product: string;
25
21
  }
26
- export declare const getPlatform: (product: Product) => Platform;
27
- export declare const getDownloadsFolder: (product: Product) => string;
28
- export declare const getDownloadHost: (product: Product) => "https://storage.googleapis.com" | "https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central";
29
- export declare const download: ({ revision, progressCallback, product, platform, downloadHost, downloadsFolder, }: {
30
- revision: string;
31
- progressCallback: (x: number, y: number) => void;
32
- product: Product;
33
- platform: Platform;
34
- downloadHost: string;
35
- downloadsFolder: string;
36
- }) => Promise<BrowserFetcherRevisionInfo | undefined>;
37
- export declare const localRevisions: (downloadsFolder: string, product: Product, platform: Platform) => Promise<string[]>;
38
- export declare const removeBrowser: (revision: string, folderPath: string) => Promise<void>;
39
- export declare const getFolderPath: (revision: string, downloadsFolder: string, platform: Platform) => string;
40
- export declare const getRevisionInfo: (revision: string, product: Product) => BrowserFetcherRevisionInfo;
22
+ export declare const downloadBrowser: () => Promise<BrowserFetcherRevisionInfo | undefined>;
23
+ export declare const getRevisionInfo: () => BrowserFetcherRevisionInfo;
41
24
  export {};
@@ -41,95 +41,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  return (mod && mod.__esModule) ? mod : { "default": mod };
42
42
  };
43
43
  Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.getRevisionInfo = exports.getFolderPath = exports.removeBrowser = exports.localRevisions = exports.download = exports.getDownloadHost = exports.getDownloadsFolder = exports.getPlatform = void 0;
45
- const https = __importStar(require("https"));
44
+ exports.getRevisionInfo = exports.downloadBrowser = void 0;
46
45
  const childProcess = __importStar(require("node:child_process"));
47
46
  const fs = __importStar(require("node:fs"));
48
- const http = __importStar(require("node:http"));
49
47
  const os = __importStar(require("node:os"));
50
48
  const path = __importStar(require("node:path"));
51
- const node_util_1 = __importDefault(require("node:util"));
52
49
  const extract_zip_1 = __importDefault(require("extract-zip"));
53
- const URL = __importStar(require("node:url"));
54
- const node_util_2 = require("node:util");
50
+ const node_util_1 = require("node:util");
55
51
  const assert_1 = require("./assert");
56
- const delete_directory_1 = require("../delete-directory");
52
+ const download_file_1 = require("../assets/download-file");
53
+ const logger_1 = require("../logger");
57
54
  const get_download_destination_1 = require("./get-download-destination");
58
- const { PUPPETEER_EXPERIMENTAL_CHROMIUM_MAC_ARM } = process.env;
59
55
  const downloadURLs = {
60
- chrome: {
61
- linux: '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip',
62
- mac: '%s/chromium-browser-snapshots/Mac/%d/%s.zip',
63
- mac_arm: '%s/chromium-browser-snapshots/Mac_Arm/%d/%s.zip',
64
- win32: '%s/chromium-browser-snapshots/Win/%d/%s.zip',
65
- win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip',
66
- },
67
- firefox: {
68
- linux: '%s/firefox-%s.en-US.%s-x86_64.tar.bz2',
69
- mac: '%s/firefox-%s.en-US.%s.dmg',
70
- win32: '%s/firefox-%s.en-US.%s.zip',
71
- win64: '%s/firefox-%s.en-US.%s.zip',
72
- },
56
+ linux: 'https://github.com/Alex313031/thorium/releases/download/M114.0.5735.205/thorium-browser_114.0.5735.205_amd64.zip',
57
+ mac: 'https://github.com/Alex313031/Thorium-Special/releases/download/M114.0.5735.205-1/Thorium_MacOS_X64.dmg',
58
+ mac_arm: 'https://github.com/Alex313031/Thorium-Special/releases/download/M114.0.5735.205-1/Thorium_MacOS_ARM.dmg',
59
+ win64: 'https://github.com/Alex313031/Thorium-Win/releases/download/M114.0.5735.205/Thorium_114.0.5735.205.zip',
73
60
  };
74
- const browserConfig = {
75
- chrome: {
76
- host: 'https://storage.googleapis.com',
77
- destination: '.chromium',
78
- },
79
- firefox: {
80
- host: 'https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central',
81
- destination: '.firefox',
82
- },
83
- };
84
- function archiveName(product, platform, revision) {
85
- switch (product) {
86
- case 'chrome':
87
- switch (platform) {
88
- case 'linux':
89
- return 'chrome-linux';
90
- case 'mac_arm':
91
- case 'mac':
92
- return 'chrome-mac';
93
- case 'win32':
94
- case 'win64':
95
- // Windows archive name changed at r591479.
96
- return parseInt(revision, 10) > 591479
97
- ? 'Thorium_107.0.5271.0\\BIN'
98
- : 'chrome-win32';
99
- default:
100
- throw new Error('unknown browser');
101
- }
102
- case 'firefox':
103
- return platform;
104
- default:
105
- throw new Error('unknown browser');
106
- }
107
- }
108
- function _downloadURL(product, platform, host, revision) {
109
- if (platform === 'win64' || platform === 'win32') {
110
- return 'https://remotionchromium-binaries.s3.eu-central-1.amazonaws.com/thorium-107.zip';
111
- }
112
- return node_util_1.default.format(downloadURLs[product][platform], host, revision, archiveName(product, platform, revision));
61
+ function getThoriumDownloadUrl(platform) {
62
+ return downloadURLs[platform];
113
63
  }
114
- function handleArm64() {
115
- let exists = fs.existsSync('/usr/bin/chromium-browser');
116
- if (exists) {
117
- return;
118
- }
119
- exists = fs.existsSync('/usr/bin/chromium');
120
- if (exists) {
121
- return;
122
- }
123
- console.error('The chromium binary is not available for arm64.' +
124
- '\nIf you are on Ubuntu, you can install with: ' +
125
- '\n\n sudo apt install chromium\n' +
126
- '\n\n sudo apt install chromium-browser\n');
127
- throw new Error();
128
- }
129
- const readdirAsync = (0, node_util_2.promisify)(fs.readdir.bind(fs));
130
- const mkdirAsync = (0, node_util_2.promisify)(fs.mkdir.bind(fs));
131
- const unlinkAsync = (0, node_util_2.promisify)(fs.unlink.bind(fs));
132
- const chmodAsync = (0, node_util_2.promisify)(fs.chmod.bind(fs));
64
+ const readdirAsync = fs.promises.readdir;
65
+ const mkdirAsync = fs.promises.mkdir;
66
+ const unlinkAsync = (0, node_util_1.promisify)(fs.unlink.bind(fs));
67
+ const chmodAsync = (0, node_util_1.promisify)(fs.chmod.bind(fs));
133
68
  function existsAsync(filePath) {
134
69
  return new Promise((resolve) => {
135
70
  fs.access(filePath, (err) => {
@@ -137,46 +72,33 @@ function existsAsync(filePath) {
137
72
  });
138
73
  });
139
74
  }
140
- const getPlatform = (product) => {
75
+ const getPlatform = () => {
141
76
  const platform = os.platform();
142
77
  switch (platform) {
143
78
  case 'darwin':
144
- switch (product) {
145
- case 'chrome':
146
- return os.arch() === 'arm64' &&
147
- PUPPETEER_EXPERIMENTAL_CHROMIUM_MAC_ARM
148
- ? 'mac_arm'
149
- : 'mac';
150
- case 'firefox':
151
- return 'mac';
152
- default:
153
- throw new Error('unknown browser');
154
- }
79
+ return os.arch() === 'arm64' ? 'mac_arm' : 'mac';
155
80
  case 'linux':
156
81
  return 'linux';
157
82
  case 'win32':
158
- return os.arch() === 'x64' ? 'win64' : 'win32';
83
+ return 'win64';
159
84
  default:
160
85
  (0, assert_1.assert)(false, 'Unsupported platform: ' + platform);
161
86
  }
162
87
  };
163
- exports.getPlatform = getPlatform;
164
- const getDownloadsFolder = (product) => {
165
- return path.join((0, get_download_destination_1.getDownloadsCacheDir)(), browserConfig[product].destination);
166
- };
167
- exports.getDownloadsFolder = getDownloadsFolder;
168
- const getDownloadHost = (product) => {
169
- return browserConfig[product].host;
88
+ const destination = '.thorium';
89
+ const getDownloadsFolder = () => {
90
+ return path.join((0, get_download_destination_1.getDownloadsCacheDir)(), destination);
170
91
  };
171
- exports.getDownloadHost = getDownloadHost;
172
- const download = async ({ revision, progressCallback, product, platform, downloadHost, downloadsFolder, }) => {
173
- const url = _downloadURL(product, platform, downloadHost, revision);
174
- const fileName = url.split('/').pop();
175
- (0, assert_1.assert)(fileName, `A malformed download URL was found: ${url}.`);
92
+ const downloadBrowser = async () => {
93
+ const platform = getPlatform();
94
+ const downloadURL = getThoriumDownloadUrl(platform);
95
+ const fileName = downloadURL.split('/').pop();
96
+ (0, assert_1.assert)(fileName, `A malformed download URL was found: ${downloadURL}.`);
97
+ const downloadsFolder = getDownloadsFolder();
176
98
  const archivePath = path.join(downloadsFolder, fileName);
177
- const outputPath = (0, exports.getFolderPath)(revision, downloadsFolder, platform);
99
+ const outputPath = getFolderPath(downloadsFolder, platform);
178
100
  if (await existsAsync(outputPath)) {
179
- return (0, exports.getRevisionInfo)(revision, product);
101
+ return (0, exports.getRevisionInfo)();
180
102
  }
181
103
  if (!(await existsAsync(downloadsFolder))) {
182
104
  await mkdirAsync(downloadsFolder, {
@@ -185,163 +107,75 @@ const download = async ({ revision, progressCallback, product, platform, downloa
185
107
  }
186
108
  // Use system Chromium builds on Linux ARM devices
187
109
  if (os.platform() !== 'darwin' && os.arch() === 'arm64') {
188
- handleArm64();
189
- return;
110
+ throw new Error('The chromium binary is not available for arm64.' +
111
+ '\nIf you are on Ubuntu, you can install with: ' +
112
+ '\n\n sudo apt install chromium\n' +
113
+ '\n\n sudo apt install chromium-browser\n');
190
114
  }
191
115
  try {
192
- await _downloadFile(url, archivePath, progressCallback);
193
- await install(archivePath, outputPath);
116
+ let lastProgress = 0;
117
+ await (0, download_file_1.downloadFile)({
118
+ url: downloadURL,
119
+ to: () => archivePath,
120
+ onProgress: (progress) => {
121
+ if (progress.downloaded > lastProgress + 10000000) {
122
+ lastProgress = progress.downloaded;
123
+ logger_1.Log.info(`Downloading Thorium - ${toMegabytes(progress.downloaded)}/${toMegabytes(progress.totalSize)}`);
124
+ }
125
+ },
126
+ });
127
+ await install({ archivePath, folderPath: outputPath });
194
128
  }
195
129
  finally {
196
130
  if (await existsAsync(archivePath)) {
197
131
  await unlinkAsync(archivePath);
198
132
  }
199
133
  }
200
- const revisionInfo = (0, exports.getRevisionInfo)(revision, product);
201
- if (revisionInfo) {
202
- await chmodAsync(revisionInfo.executablePath, 0o755);
203
- }
134
+ const revisionInfo = (0, exports.getRevisionInfo)();
135
+ await chmodAsync(revisionInfo.executablePath, 0o755);
204
136
  return revisionInfo;
205
137
  };
206
- exports.download = download;
207
- const localRevisions = async (downloadsFolder, product, platform) => {
208
- if (!(await existsAsync(downloadsFolder))) {
209
- return [];
210
- }
211
- const fileNames = await readdirAsync(downloadsFolder);
212
- return fileNames
213
- .map((fileName) => {
214
- return parseFolderPath(product, fileName);
215
- })
216
- .filter((entry) => {
217
- var _a;
218
- return (_a = (entry && entry.platform === platform)) !== null && _a !== void 0 ? _a : false;
219
- })
220
- .map((entry) => {
221
- return entry.revision;
222
- });
223
- };
224
- exports.localRevisions = localRevisions;
225
- const removeBrowser = async (revision, folderPath) => {
226
- (0, assert_1.assert)(await existsAsync(folderPath), `Failed to remove: revision ${revision} is not downloaded`);
227
- (0, delete_directory_1.deleteDirectory)(folderPath);
228
- };
229
- exports.removeBrowser = removeBrowser;
230
- const getFolderPath = (revision, downloadsFolder, platform) => {
231
- return path.resolve(downloadsFolder, `${platform}-${revision}`);
138
+ exports.downloadBrowser = downloadBrowser;
139
+ const getFolderPath = (downloadsFolder, platform) => {
140
+ return path.resolve(downloadsFolder, platform);
232
141
  };
233
- exports.getFolderPath = getFolderPath;
234
- const getExecutablePath = (product, revision) => {
235
- const downloadsFolder = (0, exports.getDownloadsFolder)(product);
236
- const platform = (0, exports.getPlatform)(product);
237
- const folderPath = (0, exports.getFolderPath)(revision, downloadsFolder, platform);
238
- if (product === 'chrome') {
239
- if (platform === 'mac' || platform === 'mac_arm') {
240
- return path.join(folderPath, archiveName(product, platform, revision), 'Chromium.app', 'Contents', 'MacOS', 'Chromium');
241
- }
242
- if (platform === 'linux') {
243
- return path.join(folderPath, archiveName(product, platform, revision), 'chrome');
244
- }
245
- if (platform === 'win32' || platform === 'win64') {
246
- return path.join(folderPath, archiveName(product, platform, revision), 'thorium.exe');
247
- }
248
- throw new Error('Unsupported platform: ' + platform);
142
+ const getExecutablePath = () => {
143
+ const downloadsFolder = getDownloadsFolder();
144
+ const platform = getPlatform();
145
+ const folderPath = getFolderPath(downloadsFolder, platform);
146
+ if (platform === 'mac' || platform === 'mac_arm') {
147
+ return path.join(folderPath, 'Thorium.app', 'Contents', 'MacOS', 'Thorium');
249
148
  }
250
- if (product === 'firefox') {
251
- if (platform === 'mac' || platform === 'mac_arm') {
252
- return path.join(folderPath, 'Firefox Nightly.app', 'Contents', 'MacOS', 'firefox');
253
- }
254
- if (platform === 'linux') {
255
- return path.join(folderPath, 'firefox', 'firefox');
256
- }
257
- if (platform === 'win32' || platform === 'win64') {
258
- return path.join(folderPath, 'firefox', 'firefox.exe');
259
- }
260
- throw new Error('Unsupported platform: ' + platform);
149
+ if (platform === 'linux') {
150
+ return path.join(folderPath, 'thorium');
261
151
  }
262
- throw new Error('Unsupported product: ' + product);
152
+ if (platform === 'win64') {
153
+ return path.join(folderPath, 'BIN', 'thorium.exe');
154
+ }
155
+ throw new Error('Can not download browser for platform: ' + platform);
263
156
  };
264
- const getRevisionInfo = (revision, product) => {
265
- const executablePath = getExecutablePath(product, revision);
266
- const downloadsFolder = (0, exports.getDownloadsFolder)(product);
267
- const platform = (0, exports.getPlatform)(product);
268
- const folderPath = (0, exports.getFolderPath)(revision, downloadsFolder, platform);
269
- const url = _downloadURL(product, platform, (0, exports.getDownloadHost)(product), revision);
157
+ const getRevisionInfo = () => {
158
+ const executablePath = getExecutablePath();
159
+ const downloadsFolder = getDownloadsFolder();
160
+ const platform = getPlatform();
161
+ const folderPath = getFolderPath(downloadsFolder, platform);
162
+ const url = getThoriumDownloadUrl(platform);
270
163
  const local = fs.existsSync(folderPath);
271
164
  return {
272
- revision,
273
165
  executablePath,
274
166
  folderPath,
275
167
  local,
276
168
  url,
277
- product,
278
169
  };
279
170
  };
280
171
  exports.getRevisionInfo = getRevisionInfo;
281
- function parseFolderPath(product, folderPath) {
282
- const name = path.basename(folderPath);
283
- const splits = name.split('-');
284
- if (splits.length !== 2) {
285
- return;
286
- }
287
- const [platform, revision] = splits;
288
- if (!revision || !platform || !(platform in downloadURLs[product])) {
289
- return;
290
- }
291
- return { product, platform, revision };
292
- }
293
- function _downloadFile(url, destinationPath, progressCallback) {
294
- let fulfill;
295
- let reject;
296
- const promise = new Promise((x, y) => {
297
- fulfill = x;
298
- reject = y;
299
- });
300
- let downloadedBytes = 0;
301
- let totalBytes = 0;
302
- let lastProgress = Date.now();
303
- function onData(chunk) {
304
- downloadedBytes += chunk.length;
305
- if (Date.now() - lastProgress > 1000) {
306
- progressCallback(downloadedBytes, totalBytes);
307
- lastProgress = Date.now();
308
- }
309
- }
310
- const request = httpRequest(url, 'GET', (response) => {
311
- if (response.statusCode !== 200) {
312
- const error = new Error(`Download failed: server returned code ${response.statusCode}. URL: ${url}`);
313
- // consume response data to free up memory
314
- response.resume();
315
- reject(error);
316
- return;
317
- }
318
- const file = fs.createWriteStream(destinationPath);
319
- file.on('close', () => {
320
- return fulfill(totalBytes);
321
- });
322
- file.on('error', (error) => {
323
- return reject(error);
324
- });
325
- response.pipe(file);
326
- totalBytes = parseInt(response.headers['content-length'], 10);
327
- response.on('data', onData);
328
- });
329
- request.on('error', (error) => {
330
- return reject(error);
331
- });
332
- return promise;
333
- }
334
- function install(archivePath, folderPath) {
172
+ async function install({ archivePath, folderPath, }) {
335
173
  if (archivePath.endsWith('.zip')) {
336
174
  return (0, extract_zip_1.default)(archivePath, { dir: folderPath });
337
175
  }
338
- if (archivePath.endsWith('.tar.bz2')) {
339
- throw new Error('bz2 currently not implemented');
340
- }
341
176
  if (archivePath.endsWith('.dmg')) {
342
- return mkdirAsync(folderPath).then(() => {
343
- return _installDMG(archivePath, folderPath);
344
- });
177
+ await mkdirAsync(folderPath);
178
+ return _installDMG(archivePath, folderPath);
345
179
  }
346
180
  throw new Error(`Unsupported archive format: ${archivePath}`);
347
181
  }
@@ -394,31 +228,7 @@ function _installDMG(dmgPath, folderPath) {
394
228
  });
395
229
  });
396
230
  }
397
- function httpRequest(url, method, response, keepAlive = true) {
398
- const urlParsed = URL.parse(url);
399
- const options = {
400
- ...urlParsed,
401
- method,
402
- headers: keepAlive
403
- ? {
404
- Connection: 'keep-alive',
405
- }
406
- : undefined,
407
- };
408
- const requestCallback = (res) => {
409
- if (res.statusCode &&
410
- res.statusCode >= 300 &&
411
- res.statusCode < 400 &&
412
- res.headers.location) {
413
- httpRequest(res.headers.location, method, response);
414
- }
415
- else {
416
- response(res);
417
- }
418
- };
419
- const request = options.protocol === 'https:'
420
- ? https.request(options, requestCallback)
421
- : http.request(options, requestCallback);
422
- request.end();
423
- return request;
231
+ function toMegabytes(bytes) {
232
+ const mb = bytes / 1024 / 1024;
233
+ return `${Math.round(mb * 10) / 10} Mb`;
424
234
  }
@@ -15,7 +15,6 @@
15
15
  */
16
16
  import type { LogLevel } from '../log-level';
17
17
  import type { BrowserConnectOptions } from './BrowserConnector';
18
- import type { Product } from './Product';
19
18
  export interface BrowserLaunchArgumentOptions {
20
19
  headless?: boolean | 'chrome';
21
20
  userDataDir?: string;
@@ -29,7 +28,6 @@ export interface LaunchOptions {
29
28
  dumpio?: boolean;
30
29
  logLevel: LogLevel;
31
30
  env?: Record<string, string | undefined>;
32
- product?: Product;
33
31
  indent: boolean;
34
32
  }
35
33
  export type PuppeteerNodeLaunchOptions = BrowserLaunchArgumentOptions & LaunchOptions & BrowserConnectOptions;
@@ -1,15 +1,10 @@
1
1
  import { HeadlessBrowser } from './Browser';
2
2
  import type { PuppeteerNodeLaunchOptions } from './LaunchOptions';
3
- import type { Product } from './Product';
4
3
  export interface ProductLauncher {
5
4
  launch(object: PuppeteerNodeLaunchOptions): Promise<HeadlessBrowser>;
6
5
  executablePath: (path?: any) => string;
7
- product: Product;
8
6
  }
9
7
  export declare class ChromeLauncher implements ProductLauncher {
10
- _preferredRevision: string;
11
- constructor(preferredRevision: string);
12
8
  launch(options: PuppeteerNodeLaunchOptions): Promise<HeadlessBrowser>;
13
9
  executablePath(): string;
14
- get product(): Product;
15
10
  }
@@ -52,9 +52,6 @@ const tmpDir = () => {
52
52
  return process.env.PUPPETEER_TMP_DIR || os.tmpdir();
53
53
  };
54
54
  class ChromeLauncher {
55
- constructor(preferredRevision) {
56
- this._preferredRevision = preferredRevision;
57
- }
58
55
  async launch(options) {
59
56
  const { args = [], dumpio = false, executablePath, env = process.env, defaultViewport, timeout = 60000, debuggingPort, indent, } = options;
60
57
  const chromeArguments = args;
@@ -69,7 +66,7 @@ class ChromeLauncher {
69
66
  chromeArguments.push(`--user-data-dir=${userDataDir}`);
70
67
  let chromeExecutable = executablePath;
71
68
  if (!chromeExecutable) {
72
- const { missingText, executablePath: exPath } = resolveExecutablePath(this);
69
+ const { missingText, executablePath: exPath } = resolveExecutablePath();
73
70
  if (missingText) {
74
71
  throw new Error(missingText);
75
72
  }
@@ -113,21 +110,15 @@ class ChromeLauncher {
113
110
  return browser;
114
111
  }
115
112
  executablePath() {
116
- const results = resolveExecutablePath(this);
113
+ const results = resolveExecutablePath();
117
114
  return results.executablePath;
118
115
  }
119
- get product() {
120
- return 'chrome';
121
- }
122
116
  }
123
117
  exports.ChromeLauncher = ChromeLauncher;
124
- function resolveExecutablePath(launcher) {
125
- const { product, _preferredRevision } = launcher;
126
- const revisionInfo = (0, BrowserFetcher_1.getRevisionInfo)(_preferredRevision, 'chrome');
127
- const firefoxHelp = `Run \`PUPPETEER_PRODUCT=firefox npm install\` to download a supported Firefox browser binary.`;
128
- const chromeHelp = `Run \`npm install\` to download the correct Chromium revision.`;
118
+ function resolveExecutablePath() {
119
+ const revisionInfo = (0, BrowserFetcher_1.getRevisionInfo)();
129
120
  const missingText = revisionInfo.local
130
121
  ? undefined
131
- : `Could not find expected browser (${product}) locally. ${product === 'chrome' ? chromeHelp : firefoxHelp}`;
122
+ : `Could not find expected browser locally.`;
132
123
  return { executablePath: revisionInfo.executablePath, missingText };
133
124
  }
@@ -17,21 +17,14 @@ import type { HeadlessBrowser } from './Browser';
17
17
  import type { BrowserConnectOptions } from './BrowserConnector';
18
18
  import type { ProductLauncher } from './Launcher';
19
19
  import type { BrowserLaunchArgumentOptions, LaunchOptions } from './LaunchOptions';
20
- import type { Product } from './Product';
21
20
  interface PuppeteerLaunchOptions extends LaunchOptions, BrowserLaunchArgumentOptions, BrowserConnectOptions {
22
- product?: Product;
23
21
  extraPrefsFirefox?: Record<string, unknown>;
24
22
  }
25
23
  export declare class PuppeteerNode {
26
24
  #private;
27
- _preferredRevision: string;
28
- constructor(settings: {
29
- preferredRevision: string;
30
- productName?: Product;
31
- });
25
+ constructor();
32
26
  launch(options: PuppeteerLaunchOptions): Promise<HeadlessBrowser>;
33
27
  executablePath(channel?: string): string;
34
28
  get _launcher(): ProductLauncher;
35
- get product(): string;
36
29
  }
37
30
  export {};