2023-02-13 10:49:50 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2023 Google Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as chrome from './chrome.js';
|
|
|
|
import * as firefox from './firefox.js';
|
2023-03-14 11:01:11 +00:00
|
|
|
import {
|
|
|
|
Browser,
|
|
|
|
BrowserPlatform,
|
|
|
|
BrowserTag,
|
|
|
|
ChromeReleaseChannel,
|
|
|
|
ProfileOptions,
|
|
|
|
} from './types.js';
|
2023-02-13 10:49:50 +00:00
|
|
|
|
|
|
|
export const downloadUrls = {
|
|
|
|
[Browser.CHROME]: chrome.resolveDownloadUrl,
|
2023-03-06 10:59:44 +00:00
|
|
|
[Browser.CHROMIUM]: chrome.resolveDownloadUrl,
|
2023-02-13 10:49:50 +00:00
|
|
|
[Browser.FIREFOX]: firefox.resolveDownloadUrl,
|
|
|
|
};
|
|
|
|
|
2023-02-13 15:10:54 +00:00
|
|
|
export const executablePathByBrowser = {
|
2023-02-15 19:41:22 +00:00
|
|
|
[Browser.CHROME]: chrome.relativeExecutablePath,
|
2023-03-06 10:59:44 +00:00
|
|
|
[Browser.CHROMIUM]: chrome.relativeExecutablePath,
|
2023-02-15 19:41:22 +00:00
|
|
|
[Browser.FIREFOX]: firefox.relativeExecutablePath,
|
2023-02-13 15:10:54 +00:00
|
|
|
};
|
|
|
|
|
2023-03-14 17:22:25 +00:00
|
|
|
export {Browser, BrowserPlatform, ChromeReleaseChannel};
|
2023-02-21 07:27:02 +00:00
|
|
|
|
2023-02-21 16:15:49 +00:00
|
|
|
export async function resolveBuildId(
|
2023-02-21 07:27:02 +00:00
|
|
|
browser: Browser,
|
2023-02-21 14:19:06 +00:00
|
|
|
platform: BrowserPlatform,
|
2023-02-21 07:27:02 +00:00
|
|
|
tag: string
|
|
|
|
): Promise<string> {
|
|
|
|
switch (browser) {
|
|
|
|
case Browser.FIREFOX:
|
|
|
|
switch (tag as BrowserTag) {
|
|
|
|
case BrowserTag.LATEST:
|
2023-02-21 16:15:49 +00:00
|
|
|
return await firefox.resolveBuildId('FIREFOX_NIGHTLY');
|
2023-02-21 07:27:02 +00:00
|
|
|
}
|
2023-02-21 14:19:06 +00:00
|
|
|
case Browser.CHROME:
|
2023-03-06 10:59:44 +00:00
|
|
|
case Browser.CHROMIUM:
|
2023-02-21 14:19:06 +00:00
|
|
|
switch (tag as BrowserTag) {
|
|
|
|
case BrowserTag.LATEST:
|
2023-02-21 16:15:49 +00:00
|
|
|
return await chrome.resolveBuildId(platform, 'latest');
|
2023-02-21 14:19:06 +00:00
|
|
|
}
|
2023-02-21 07:27:02 +00:00
|
|
|
}
|
2023-02-21 16:15:49 +00:00
|
|
|
// We assume the tag is the buildId if it didn't match any keywords.
|
2023-02-21 07:27:02 +00:00
|
|
|
return tag;
|
|
|
|
}
|
2023-03-13 15:43:43 +00:00
|
|
|
|
|
|
|
export async function createProfile(
|
|
|
|
browser: Browser,
|
|
|
|
opts: ProfileOptions
|
|
|
|
): Promise<void> {
|
|
|
|
switch (browser) {
|
|
|
|
case Browser.FIREFOX:
|
|
|
|
return await firefox.createProfile(opts);
|
|
|
|
case Browser.CHROME:
|
|
|
|
case Browser.CHROMIUM:
|
|
|
|
throw new Error(`Profile creation is not support for ${browser} yet`);
|
|
|
|
}
|
|
|
|
}
|
2023-03-14 11:01:11 +00:00
|
|
|
|
|
|
|
export function resolveSystemExecutablePath(
|
|
|
|
browser: Browser,
|
|
|
|
platform: BrowserPlatform,
|
|
|
|
channel: ChromeReleaseChannel
|
|
|
|
): string {
|
|
|
|
switch (browser) {
|
|
|
|
case Browser.FIREFOX:
|
|
|
|
throw new Error(
|
|
|
|
'System browser detection is not supported for Firefox yet.'
|
|
|
|
);
|
|
|
|
case Browser.CHROME:
|
|
|
|
case Browser.CHROMIUM:
|
|
|
|
return chrome.resolveSystemExecutablePath(platform, channel);
|
|
|
|
}
|
|
|
|
}
|