chrome.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. "use strict";
  2. /**
  3. * Copyright 2023 Google Inc. All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. var __importDefault = (this && this.__importDefault) || function (mod) {
  18. return (mod && mod.__esModule) ? mod : { "default": mod };
  19. };
  20. Object.defineProperty(exports, "__esModule", { value: true });
  21. exports.resolveSystemExecutablePath = exports.resolveBuildId = exports.getLastKnownGoodReleaseForChannel = exports.relativeExecutablePath = exports.resolveDownloadPath = exports.resolveDownloadUrl = void 0;
  22. const path_1 = __importDefault(require("path"));
  23. const httpUtil_js_1 = require("../httpUtil.js");
  24. const types_js_1 = require("./types.js");
  25. function folder(platform) {
  26. switch (platform) {
  27. case types_js_1.BrowserPlatform.LINUX:
  28. return 'linux64';
  29. case types_js_1.BrowserPlatform.MAC_ARM:
  30. return 'mac-arm64';
  31. case types_js_1.BrowserPlatform.MAC:
  32. return 'mac-x64';
  33. case types_js_1.BrowserPlatform.WIN32:
  34. return 'win32';
  35. case types_js_1.BrowserPlatform.WIN64:
  36. return 'win64';
  37. }
  38. }
  39. function resolveDownloadUrl(platform, buildId, baseUrl = 'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing') {
  40. return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
  41. }
  42. exports.resolveDownloadUrl = resolveDownloadUrl;
  43. function resolveDownloadPath(platform, buildId) {
  44. return [buildId, folder(platform), `chrome-${folder(platform)}.zip`];
  45. }
  46. exports.resolveDownloadPath = resolveDownloadPath;
  47. function relativeExecutablePath(platform, _buildId) {
  48. switch (platform) {
  49. case types_js_1.BrowserPlatform.MAC:
  50. case types_js_1.BrowserPlatform.MAC_ARM:
  51. return path_1.default.join('chrome-' + folder(platform), 'Google Chrome for Testing.app', 'Contents', 'MacOS', 'Google Chrome for Testing');
  52. case types_js_1.BrowserPlatform.LINUX:
  53. return path_1.default.join('chrome-linux64', 'chrome');
  54. case types_js_1.BrowserPlatform.WIN32:
  55. case types_js_1.BrowserPlatform.WIN64:
  56. return path_1.default.join('chrome-' + folder(platform), 'chrome.exe');
  57. }
  58. }
  59. exports.relativeExecutablePath = relativeExecutablePath;
  60. async function getLastKnownGoodReleaseForChannel(channel) {
  61. const data = (await (0, httpUtil_js_1.getJSON)(new URL('https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json')));
  62. for (const channel of Object.keys(data.channels)) {
  63. data.channels[channel.toLowerCase()] = data.channels[channel];
  64. delete data.channels[channel];
  65. }
  66. return data.channels[channel];
  67. }
  68. exports.getLastKnownGoodReleaseForChannel = getLastKnownGoodReleaseForChannel;
  69. async function resolveBuildId(_platform, channel) {
  70. return (await getLastKnownGoodReleaseForChannel(channel)).version;
  71. }
  72. exports.resolveBuildId = resolveBuildId;
  73. function resolveSystemExecutablePath(platform, channel) {
  74. switch (platform) {
  75. case types_js_1.BrowserPlatform.WIN64:
  76. case types_js_1.BrowserPlatform.WIN32:
  77. switch (channel) {
  78. case types_js_1.ChromeReleaseChannel.STABLE:
  79. return `${process.env['PROGRAMFILES']}\\Google\\Chrome\\Application\\chrome.exe`;
  80. case types_js_1.ChromeReleaseChannel.BETA:
  81. return `${process.env['PROGRAMFILES']}\\Google\\Chrome Beta\\Application\\chrome.exe`;
  82. case types_js_1.ChromeReleaseChannel.CANARY:
  83. return `${process.env['PROGRAMFILES']}\\Google\\Chrome SxS\\Application\\chrome.exe`;
  84. case types_js_1.ChromeReleaseChannel.DEV:
  85. return `${process.env['PROGRAMFILES']}\\Google\\Chrome Dev\\Application\\chrome.exe`;
  86. }
  87. case types_js_1.BrowserPlatform.MAC_ARM:
  88. case types_js_1.BrowserPlatform.MAC:
  89. switch (channel) {
  90. case types_js_1.ChromeReleaseChannel.STABLE:
  91. return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
  92. case types_js_1.ChromeReleaseChannel.BETA:
  93. return '/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta';
  94. case types_js_1.ChromeReleaseChannel.CANARY:
  95. return '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary';
  96. case types_js_1.ChromeReleaseChannel.DEV:
  97. return '/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev';
  98. }
  99. case types_js_1.BrowserPlatform.LINUX:
  100. switch (channel) {
  101. case types_js_1.ChromeReleaseChannel.STABLE:
  102. return '/opt/google/chrome/chrome';
  103. case types_js_1.ChromeReleaseChannel.BETA:
  104. return '/opt/google/chrome-beta/chrome';
  105. case types_js_1.ChromeReleaseChannel.DEV:
  106. return '/opt/google/chrome-unstable/chrome';
  107. }
  108. }
  109. throw new Error(`Unable to detect browser executable path for '${channel}' on ${platform}.`);
  110. }
  111. exports.resolveSystemExecutablePath = resolveSystemExecutablePath;
  112. //# sourceMappingURL=chrome.js.map