chromium.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Copyright 2023 Google Inc. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import path from 'path';
  17. import { getText } from '../httpUtil.js';
  18. import { BrowserPlatform } from './types.js';
  19. function archive(platform, buildId) {
  20. switch (platform) {
  21. case BrowserPlatform.LINUX:
  22. return 'chrome-linux';
  23. case BrowserPlatform.MAC_ARM:
  24. case BrowserPlatform.MAC:
  25. return 'chrome-mac';
  26. case BrowserPlatform.WIN32:
  27. case BrowserPlatform.WIN64:
  28. // Windows archive name changed at r591479.
  29. return parseInt(buildId, 10) > 591479 ? 'chrome-win' : 'chrome-win32';
  30. }
  31. }
  32. function folder(platform) {
  33. switch (platform) {
  34. case BrowserPlatform.LINUX:
  35. return 'Linux_x64';
  36. case BrowserPlatform.MAC_ARM:
  37. return 'Mac_Arm';
  38. case BrowserPlatform.MAC:
  39. return 'Mac';
  40. case BrowserPlatform.WIN32:
  41. return 'Win';
  42. case BrowserPlatform.WIN64:
  43. return 'Win_x64';
  44. }
  45. }
  46. export function resolveDownloadUrl(platform, buildId, baseUrl = 'https://storage.googleapis.com/chromium-browser-snapshots') {
  47. return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
  48. }
  49. export function resolveDownloadPath(platform, buildId) {
  50. return [folder(platform), buildId, `${archive(platform, buildId)}.zip`];
  51. }
  52. export function relativeExecutablePath(platform, _buildId) {
  53. switch (platform) {
  54. case BrowserPlatform.MAC:
  55. case BrowserPlatform.MAC_ARM:
  56. return path.join('chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium');
  57. case BrowserPlatform.LINUX:
  58. return path.join('chrome-linux', 'chrome');
  59. case BrowserPlatform.WIN32:
  60. case BrowserPlatform.WIN64:
  61. return path.join('chrome-win', 'chrome.exe');
  62. }
  63. }
  64. export async function resolveBuildId(platform) {
  65. return await getText(new URL(`https://storage.googleapis.com/chromium-browser-snapshots/${folder(platform)}/LAST_CHANGE`));
  66. }
  67. //# sourceMappingURL=chromium.js.map