browser-data.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  18. if (k2 === undefined) k2 = k;
  19. var desc = Object.getOwnPropertyDescriptor(m, k);
  20. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  21. desc = { enumerable: true, get: function() { return m[k]; } };
  22. }
  23. Object.defineProperty(o, k2, desc);
  24. }) : (function(o, m, k, k2) {
  25. if (k2 === undefined) k2 = k;
  26. o[k2] = m[k];
  27. }));
  28. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  29. Object.defineProperty(o, "default", { enumerable: true, value: v });
  30. }) : function(o, v) {
  31. o["default"] = v;
  32. });
  33. var __importStar = (this && this.__importStar) || function (mod) {
  34. if (mod && mod.__esModule) return mod;
  35. var result = {};
  36. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  37. __setModuleDefault(result, mod);
  38. return result;
  39. };
  40. Object.defineProperty(exports, "__esModule", { value: true });
  41. exports.resolveSystemExecutablePath = exports.createProfile = exports.resolveBuildId = exports.ChromeReleaseChannel = exports.BrowserPlatform = exports.Browser = exports.executablePathByBrowser = exports.downloadPaths = exports.downloadUrls = void 0;
  42. const chrome = __importStar(require("./chrome.js"));
  43. const chromedriver = __importStar(require("./chromedriver.js"));
  44. const chromium = __importStar(require("./chromium.js"));
  45. const firefox = __importStar(require("./firefox.js"));
  46. const types_js_1 = require("./types.js");
  47. Object.defineProperty(exports, "Browser", { enumerable: true, get: function () { return types_js_1.Browser; } });
  48. Object.defineProperty(exports, "BrowserPlatform", { enumerable: true, get: function () { return types_js_1.BrowserPlatform; } });
  49. Object.defineProperty(exports, "ChromeReleaseChannel", { enumerable: true, get: function () { return types_js_1.ChromeReleaseChannel; } });
  50. exports.downloadUrls = {
  51. [types_js_1.Browser.CHROMEDRIVER]: chromedriver.resolveDownloadUrl,
  52. [types_js_1.Browser.CHROME]: chrome.resolveDownloadUrl,
  53. [types_js_1.Browser.CHROMIUM]: chromium.resolveDownloadUrl,
  54. [types_js_1.Browser.FIREFOX]: firefox.resolveDownloadUrl,
  55. };
  56. exports.downloadPaths = {
  57. [types_js_1.Browser.CHROMEDRIVER]: chromedriver.resolveDownloadPath,
  58. [types_js_1.Browser.CHROME]: chrome.resolveDownloadPath,
  59. [types_js_1.Browser.CHROMIUM]: chromium.resolveDownloadPath,
  60. [types_js_1.Browser.FIREFOX]: firefox.resolveDownloadPath,
  61. };
  62. exports.executablePathByBrowser = {
  63. [types_js_1.Browser.CHROMEDRIVER]: chromedriver.relativeExecutablePath,
  64. [types_js_1.Browser.CHROME]: chrome.relativeExecutablePath,
  65. [types_js_1.Browser.CHROMIUM]: chromium.relativeExecutablePath,
  66. [types_js_1.Browser.FIREFOX]: firefox.relativeExecutablePath,
  67. };
  68. /**
  69. * @public
  70. */
  71. async function resolveBuildId(browser, platform, tag) {
  72. switch (browser) {
  73. case types_js_1.Browser.FIREFOX:
  74. switch (tag) {
  75. case types_js_1.BrowserTag.LATEST:
  76. return await firefox.resolveBuildId('FIREFOX_NIGHTLY');
  77. case types_js_1.BrowserTag.BETA:
  78. case types_js_1.BrowserTag.CANARY:
  79. case types_js_1.BrowserTag.DEV:
  80. case types_js_1.BrowserTag.STABLE:
  81. throw new Error(`${tag} is not supported for ${browser}. Use 'latest' instead.`);
  82. }
  83. case types_js_1.Browser.CHROME:
  84. switch (tag) {
  85. case types_js_1.BrowserTag.LATEST:
  86. return await chrome.resolveBuildId(platform, types_js_1.ChromeReleaseChannel.CANARY);
  87. case types_js_1.BrowserTag.BETA:
  88. return await chrome.resolveBuildId(platform, types_js_1.ChromeReleaseChannel.BETA);
  89. case types_js_1.BrowserTag.CANARY:
  90. return await chrome.resolveBuildId(platform, types_js_1.ChromeReleaseChannel.CANARY);
  91. case types_js_1.BrowserTag.DEV:
  92. return await chrome.resolveBuildId(platform, types_js_1.ChromeReleaseChannel.DEV);
  93. case types_js_1.BrowserTag.STABLE:
  94. return await chrome.resolveBuildId(platform, types_js_1.ChromeReleaseChannel.STABLE);
  95. }
  96. case types_js_1.Browser.CHROMEDRIVER:
  97. switch (tag) {
  98. case types_js_1.BrowserTag.LATEST:
  99. case types_js_1.BrowserTag.CANARY:
  100. return await chromedriver.resolveBuildId(types_js_1.ChromeReleaseChannel.CANARY);
  101. case types_js_1.BrowserTag.BETA:
  102. return await chromedriver.resolveBuildId(types_js_1.ChromeReleaseChannel.BETA);
  103. case types_js_1.BrowserTag.DEV:
  104. return await chromedriver.resolveBuildId(types_js_1.ChromeReleaseChannel.DEV);
  105. case types_js_1.BrowserTag.STABLE:
  106. return await chromedriver.resolveBuildId(types_js_1.ChromeReleaseChannel.STABLE);
  107. }
  108. case types_js_1.Browser.CHROMIUM:
  109. switch (tag) {
  110. case types_js_1.BrowserTag.LATEST:
  111. return await chromium.resolveBuildId(platform);
  112. case types_js_1.BrowserTag.BETA:
  113. case types_js_1.BrowserTag.CANARY:
  114. case types_js_1.BrowserTag.DEV:
  115. case types_js_1.BrowserTag.STABLE:
  116. throw new Error(`${tag} is not supported for ${browser}. Use 'latest' instead.`);
  117. }
  118. }
  119. // We assume the tag is the buildId if it didn't match any keywords.
  120. return tag;
  121. }
  122. exports.resolveBuildId = resolveBuildId;
  123. /**
  124. * @public
  125. */
  126. async function createProfile(browser, opts) {
  127. switch (browser) {
  128. case types_js_1.Browser.FIREFOX:
  129. return await firefox.createProfile(opts);
  130. case types_js_1.Browser.CHROME:
  131. case types_js_1.Browser.CHROMIUM:
  132. throw new Error(`Profile creation is not support for ${browser} yet`);
  133. }
  134. }
  135. exports.createProfile = createProfile;
  136. /**
  137. * @public
  138. */
  139. function resolveSystemExecutablePath(browser, platform, channel) {
  140. switch (browser) {
  141. case types_js_1.Browser.CHROMEDRIVER:
  142. case types_js_1.Browser.FIREFOX:
  143. case types_js_1.Browser.CHROMIUM:
  144. throw new Error(`System browser detection is not supported for ${browser} yet.`);
  145. case types_js_1.Browser.CHROME:
  146. return chrome.resolveSystemExecutablePath(platform, channel);
  147. }
  148. }
  149. exports.resolveSystemExecutablePath = resolveSystemExecutablePath;
  150. //# sourceMappingURL=browser-data.js.map