chrome.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 { getJSON } from '../httpUtil.js';
  18. import { BrowserPlatform, ChromeReleaseChannel } from './types.js';
  19. function folder(platform) {
  20. switch (platform) {
  21. case BrowserPlatform.LINUX:
  22. return 'linux64';
  23. case BrowserPlatform.MAC_ARM:
  24. return 'mac-arm64';
  25. case BrowserPlatform.MAC:
  26. return 'mac-x64';
  27. case BrowserPlatform.WIN32:
  28. return 'win32';
  29. case BrowserPlatform.WIN64:
  30. return 'win64';
  31. }
  32. }
  33. export function resolveDownloadUrl(platform, buildId, baseUrl = 'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing') {
  34. return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
  35. }
  36. export function resolveDownloadPath(platform, buildId) {
  37. return [buildId, folder(platform), `chrome-${folder(platform)}.zip`];
  38. }
  39. export function relativeExecutablePath(platform, _buildId) {
  40. switch (platform) {
  41. case BrowserPlatform.MAC:
  42. case BrowserPlatform.MAC_ARM:
  43. return path.join('chrome-' + folder(platform), 'Google Chrome for Testing.app', 'Contents', 'MacOS', 'Google Chrome for Testing');
  44. case BrowserPlatform.LINUX:
  45. return path.join('chrome-linux64', 'chrome');
  46. case BrowserPlatform.WIN32:
  47. case BrowserPlatform.WIN64:
  48. return path.join('chrome-' + folder(platform), 'chrome.exe');
  49. }
  50. }
  51. export async function getLastKnownGoodReleaseForChannel(channel) {
  52. const data = (await getJSON(new URL('https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json')));
  53. for (const channel of Object.keys(data.channels)) {
  54. data.channels[channel.toLowerCase()] = data.channels[channel];
  55. delete data.channels[channel];
  56. }
  57. return data.channels[channel];
  58. }
  59. export async function resolveBuildId(_platform, channel) {
  60. return (await getLastKnownGoodReleaseForChannel(channel)).version;
  61. }
  62. export function resolveSystemExecutablePath(platform, channel) {
  63. switch (platform) {
  64. case BrowserPlatform.WIN64:
  65. case BrowserPlatform.WIN32:
  66. switch (channel) {
  67. case ChromeReleaseChannel.STABLE:
  68. return `${process.env['PROGRAMFILES']}\\Google\\Chrome\\Application\\chrome.exe`;
  69. case ChromeReleaseChannel.BETA:
  70. return `${process.env['PROGRAMFILES']}\\Google\\Chrome Beta\\Application\\chrome.exe`;
  71. case ChromeReleaseChannel.CANARY:
  72. return `${process.env['PROGRAMFILES']}\\Google\\Chrome SxS\\Application\\chrome.exe`;
  73. case ChromeReleaseChannel.DEV:
  74. return `${process.env['PROGRAMFILES']}\\Google\\Chrome Dev\\Application\\chrome.exe`;
  75. }
  76. case BrowserPlatform.MAC_ARM:
  77. case BrowserPlatform.MAC:
  78. switch (channel) {
  79. case ChromeReleaseChannel.STABLE:
  80. return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
  81. case ChromeReleaseChannel.BETA:
  82. return '/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta';
  83. case ChromeReleaseChannel.CANARY:
  84. return '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary';
  85. case ChromeReleaseChannel.DEV:
  86. return '/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev';
  87. }
  88. case BrowserPlatform.LINUX:
  89. switch (channel) {
  90. case ChromeReleaseChannel.STABLE:
  91. return '/opt/google/chrome/chrome';
  92. case ChromeReleaseChannel.BETA:
  93. return '/opt/google/chrome-beta/chrome';
  94. case ChromeReleaseChannel.DEV:
  95. return '/opt/google/chrome-unstable/chrome';
  96. }
  97. }
  98. throw new Error(`Unable to detect browser executable path for '${channel}' on ${platform}.`);
  99. }
  100. //# sourceMappingURL=chrome.js.map