browser-data.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 * as chrome from './chrome.js';
  17. import * as chromedriver from './chromedriver.js';
  18. import * as chromium from './chromium.js';
  19. import * as firefox from './firefox.js';
  20. import { Browser, BrowserPlatform, BrowserTag, ChromeReleaseChannel, } from './types.js';
  21. export const downloadUrls = {
  22. [Browser.CHROMEDRIVER]: chromedriver.resolveDownloadUrl,
  23. [Browser.CHROME]: chrome.resolveDownloadUrl,
  24. [Browser.CHROMIUM]: chromium.resolveDownloadUrl,
  25. [Browser.FIREFOX]: firefox.resolveDownloadUrl,
  26. };
  27. export const downloadPaths = {
  28. [Browser.CHROMEDRIVER]: chromedriver.resolveDownloadPath,
  29. [Browser.CHROME]: chrome.resolveDownloadPath,
  30. [Browser.CHROMIUM]: chromium.resolveDownloadPath,
  31. [Browser.FIREFOX]: firefox.resolveDownloadPath,
  32. };
  33. export const executablePathByBrowser = {
  34. [Browser.CHROMEDRIVER]: chromedriver.relativeExecutablePath,
  35. [Browser.CHROME]: chrome.relativeExecutablePath,
  36. [Browser.CHROMIUM]: chromium.relativeExecutablePath,
  37. [Browser.FIREFOX]: firefox.relativeExecutablePath,
  38. };
  39. export { Browser, BrowserPlatform, ChromeReleaseChannel };
  40. /**
  41. * @public
  42. */
  43. export async function resolveBuildId(browser, platform, tag) {
  44. switch (browser) {
  45. case Browser.FIREFOX:
  46. switch (tag) {
  47. case BrowserTag.LATEST:
  48. return await firefox.resolveBuildId('FIREFOX_NIGHTLY');
  49. case BrowserTag.BETA:
  50. case BrowserTag.CANARY:
  51. case BrowserTag.DEV:
  52. case BrowserTag.STABLE:
  53. throw new Error(`${tag} is not supported for ${browser}. Use 'latest' instead.`);
  54. }
  55. case Browser.CHROME:
  56. switch (tag) {
  57. case BrowserTag.LATEST:
  58. return await chrome.resolveBuildId(platform, ChromeReleaseChannel.CANARY);
  59. case BrowserTag.BETA:
  60. return await chrome.resolveBuildId(platform, ChromeReleaseChannel.BETA);
  61. case BrowserTag.CANARY:
  62. return await chrome.resolveBuildId(platform, ChromeReleaseChannel.CANARY);
  63. case BrowserTag.DEV:
  64. return await chrome.resolveBuildId(platform, ChromeReleaseChannel.DEV);
  65. case BrowserTag.STABLE:
  66. return await chrome.resolveBuildId(platform, ChromeReleaseChannel.STABLE);
  67. }
  68. case Browser.CHROMEDRIVER:
  69. switch (tag) {
  70. case BrowserTag.LATEST:
  71. case BrowserTag.CANARY:
  72. return await chromedriver.resolveBuildId(ChromeReleaseChannel.CANARY);
  73. case BrowserTag.BETA:
  74. return await chromedriver.resolveBuildId(ChromeReleaseChannel.BETA);
  75. case BrowserTag.DEV:
  76. return await chromedriver.resolveBuildId(ChromeReleaseChannel.DEV);
  77. case BrowserTag.STABLE:
  78. return await chromedriver.resolveBuildId(ChromeReleaseChannel.STABLE);
  79. }
  80. case Browser.CHROMIUM:
  81. switch (tag) {
  82. case BrowserTag.LATEST:
  83. return await chromium.resolveBuildId(platform);
  84. case BrowserTag.BETA:
  85. case BrowserTag.CANARY:
  86. case BrowserTag.DEV:
  87. case BrowserTag.STABLE:
  88. throw new Error(`${tag} is not supported for ${browser}. Use 'latest' instead.`);
  89. }
  90. }
  91. // We assume the tag is the buildId if it didn't match any keywords.
  92. return tag;
  93. }
  94. /**
  95. * @public
  96. */
  97. export async function createProfile(browser, opts) {
  98. switch (browser) {
  99. case Browser.FIREFOX:
  100. return await firefox.createProfile(opts);
  101. case Browser.CHROME:
  102. case Browser.CHROMIUM:
  103. throw new Error(`Profile creation is not support for ${browser} yet`);
  104. }
  105. }
  106. /**
  107. * @public
  108. */
  109. export function resolveSystemExecutablePath(browser, platform, channel) {
  110. switch (browser) {
  111. case Browser.CHROMEDRIVER:
  112. case Browser.FIREFOX:
  113. case Browser.CHROMIUM:
  114. throw new Error(`System browser detection is not supported for ${browser} yet.`);
  115. case Browser.CHROME:
  116. return chrome.resolveSystemExecutablePath(platform, channel);
  117. }
  118. }
  119. //# sourceMappingURL=browser-data.js.map