@xlinklight/browser-extension-tools 1.0.0-rc.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,41 +1,41 @@
1
- (function initializeLinkLightSidePanelTranslations(global) {
2
- function applySidePanelTranslations({
3
- documentRef = global.document,
4
- t,
5
- locale,
6
- titleKey = "extensionName",
7
- languageInput,
8
- languagePreference,
9
- safetyNote,
10
- onAfterStaticTranslations,
11
- }) {
12
- documentRef.documentElement.lang = locale;
13
- documentRef.title = t(titleKey);
14
-
15
- for (const element of documentRef.querySelectorAll("[data-i18n]")) {
16
- element.textContent = t(element.dataset.i18n);
17
- }
18
-
19
- for (const element of documentRef.querySelectorAll("[data-i18n-placeholder]")) {
20
- element.setAttribute("placeholder", t(element.dataset.i18nPlaceholder));
21
- }
22
-
23
- for (const element of documentRef.querySelectorAll("[data-i18n-aria-label]")) {
24
- element.setAttribute("aria-label", t(element.dataset.i18nAriaLabel));
25
- }
26
-
27
- for (const element of documentRef.querySelectorAll("[data-i18n-title]")) {
28
- const values = {};
29
- if (element.dataset.i18nTitleFeatureKey) {
30
- values.feature = t(element.dataset.i18nTitleFeatureKey);
31
- }
32
- element.setAttribute("title", t(element.dataset.i18nTitle, values));
33
- }
34
-
35
- if (safetyNote) safetyNote.textContent = t("safetyNote");
36
- if (languageInput) languageInput.value = languagePreference;
37
- if (typeof onAfterStaticTranslations === "function") onAfterStaticTranslations();
38
- }
39
-
40
- global.LinkLightSidePanelTranslations = { applySidePanelTranslations };
41
- })(globalThis);
1
+ (function initializeLinkLightSidePanelTranslations(global) {
2
+ function applySidePanelTranslations({
3
+ documentRef = global.document,
4
+ t,
5
+ locale,
6
+ titleKey = "extensionName",
7
+ languageInput,
8
+ languagePreference,
9
+ safetyNote,
10
+ onAfterStaticTranslations,
11
+ }) {
12
+ documentRef.documentElement.lang = locale;
13
+ documentRef.title = t(titleKey);
14
+
15
+ for (const element of documentRef.querySelectorAll("[data-i18n]")) {
16
+ element.textContent = t(element.dataset.i18n);
17
+ }
18
+
19
+ for (const element of documentRef.querySelectorAll("[data-i18n-placeholder]")) {
20
+ element.setAttribute("placeholder", t(element.dataset.i18nPlaceholder));
21
+ }
22
+
23
+ for (const element of documentRef.querySelectorAll("[data-i18n-aria-label]")) {
24
+ element.setAttribute("aria-label", t(element.dataset.i18nAriaLabel));
25
+ }
26
+
27
+ for (const element of documentRef.querySelectorAll("[data-i18n-title]")) {
28
+ const values = {};
29
+ if (element.dataset.i18nTitleFeatureKey) {
30
+ values.feature = t(element.dataset.i18nTitleFeatureKey);
31
+ }
32
+ element.setAttribute("title", t(element.dataset.i18nTitle, values));
33
+ }
34
+
35
+ if (safetyNote) safetyNote.textContent = t("safetyNote");
36
+ if (languageInput) languageInput.value = languagePreference;
37
+ if (typeof onAfterStaticTranslations === "function") onAfterStaticTranslations();
38
+ }
39
+
40
+ global.LinkLightSidePanelTranslations = { applySidePanelTranslations };
41
+ })(globalThis);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xlinklight/browser-extension-tools",
3
- "version": "1.0.0-rc.0",
3
+ "version": "1.0.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,231 +1,231 @@
1
- import { createHash } from "node:crypto";
2
- import { existsSync, readdirSync, statSync } from "node:fs";
3
- import path from "node:path";
4
- import { chromeExtensionsUrl, getArgValue, getChromeLaunchExtensionDirs, getProfileDirForExtensions, getProjectPaths, getRequestedAppUrl, getRequestedBrowser, getRequestedExtensions } from "./cli.mjs";
5
-
6
- export function normalizeChromeExtensionPath(extensionPath, platform) {
7
- const pathApi = platform === "win32" ? path.win32 : path.posix;
8
- const resolvedPath = pathApi.resolve(extensionPath);
9
-
10
- if (platform !== "win32") {
11
- return resolvedPath;
12
- }
13
-
14
- return resolvedPath.replace(/^([a-z]):/, (_, driveLetter) => `${driveLetter.toUpperCase()}:`);
15
- }
16
-
17
- export function getChromeExtensionIdForPath(extensionPath, { platform = process.platform } = {}) {
18
- const normalizedPath = normalizeChromeExtensionPath(extensionPath, platform);
19
- const pathBytes = platform === "win32" ? Buffer.from(normalizedPath, "utf16le") : Buffer.from(normalizedPath);
20
- const digest = createHash("sha256").update(pathBytes).digest("hex").slice(0, 32);
21
-
22
- return digest.replace(/[0-9a-f]/g, (character) => "abcdefghijklmnop"[Number.parseInt(character, 16)]);
23
- }
24
-
25
- export function getChromeExecutableName(platform) {
26
- if (platform === "win32") return "chrome.exe";
27
- if (platform === "darwin") return "Google Chrome for Testing";
28
- return "chrome";
29
- }
30
-
31
- export function findExecutableBelow(directory, executableName) {
32
- const entries = readdirSync(directory, { withFileTypes: true });
33
-
34
- for (const entry of entries) {
35
- const entryPath = path.join(directory, entry.name);
36
- if (entry.isFile() && entry.name === executableName) {
37
- return entryPath;
38
- }
39
- if (entry.isDirectory()) {
40
- const foundPath = findExecutableBelow(entryPath, executableName);
41
- if (foundPath) return foundPath;
42
- }
43
- }
44
-
45
- return null;
46
- }
47
-
48
- export function findLocalChromeForTesting({
49
- rootDir = process.cwd(),
50
- platform = process.platform,
51
- exists = existsSync,
52
- } = {}) {
53
- const { chromeForTestingDir } = getProjectPaths(rootDir);
54
- if (!exists(chromeForTestingDir)) {
55
- return null;
56
- }
57
-
58
- try {
59
- if (!statSync(chromeForTestingDir).isDirectory()) {
60
- return null;
61
- }
62
- return findExecutableBelow(chromeForTestingDir, getChromeExecutableName(platform));
63
- } catch (error) {
64
- if (error?.code === "ENOENT") {
65
- return null;
66
- }
67
- throw error;
68
- }
69
- }
70
-
71
- export function isLikelyGoogleChromeOrChromeForTesting(chromePath) {
72
- const normalizedPath = chromePath.toLowerCase().replaceAll("\\", "/");
73
-
74
- return (
75
- normalizedPath.includes("chrome for testing") ||
76
- normalizedPath.includes("chrome-for-testing") ||
77
- normalizedPath.includes("chrome-win64") ||
78
- normalizedPath.includes("/google/chrome/application/chrome.exe") ||
79
- normalizedPath.endsWith("/google chrome")
80
- );
81
- }
82
-
83
- export function candidateChromePaths({ browser, env, platform }) {
84
- if (platform === "win32") {
85
- if (browser === "chrome") {
86
- return [
87
- env.CHROME_FOR_TESTING_PATH,
88
- env.LOCALAPPDATA && path.join(env.LOCALAPPDATA, "Google", "Chrome", "Application", "chrome.exe"),
89
- env.PROGRAMFILES && path.join(env.PROGRAMFILES, "Google", "Chrome", "Application", "chrome.exe"),
90
- env["PROGRAMFILES(X86)"] && path.join(env["PROGRAMFILES(X86)"], "Google", "Chrome", "Application", "chrome.exe"),
91
- String.raw`C:\Program Files\Google\Chrome\Application\chrome.exe`,
92
- String.raw`C:\Program Files (x86)\Google\Chrome\Application\chrome.exe`,
93
- ].filter(Boolean);
94
- }
95
-
96
- return [
97
- env.CHROME_FOR_TESTING_PATH,
98
- env.LOCALAPPDATA && path.join(env.LOCALAPPDATA, "Chromium", "Application", "chrome.exe"),
99
- env.PROGRAMFILES && path.join(env.PROGRAMFILES, "Chromium", "Application", "chrome.exe"),
100
- env["PROGRAMFILES(X86)"] && path.join(env["PROGRAMFILES(X86)"], "Chromium", "Application", "chrome.exe"),
101
- env.LOCALAPPDATA && path.join(env.LOCALAPPDATA, "Microsoft", "Edge", "Application", "msedge.exe"),
102
- env.PROGRAMFILES && path.join(env.PROGRAMFILES, "Microsoft", "Edge", "Application", "msedge.exe"),
103
- env["PROGRAMFILES(X86)"] && path.join(env["PROGRAMFILES(X86)"], "Microsoft", "Edge", "Application", "msedge.exe"),
104
- env.LOCALAPPDATA && path.join(env.LOCALAPPDATA, "Google", "Chrome", "Application", "chrome.exe"),
105
- env.PROGRAMFILES && path.join(env.PROGRAMFILES, "Google", "Chrome", "Application", "chrome.exe"),
106
- env["PROGRAMFILES(X86)"] && path.join(env["PROGRAMFILES(X86)"], "Google", "Chrome", "Application", "chrome.exe"),
107
- String.raw`C:\Program Files\Microsoft\Edge\Application\msedge.exe`,
108
- String.raw`C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe`,
109
- String.raw`C:\Program Files\Google\Chrome\Application\chrome.exe`,
110
- String.raw`C:\Program Files (x86)\Google\Chrome\Application\chrome.exe`,
111
- ].filter(Boolean);
112
- }
113
-
114
- if (platform === "darwin") {
115
- return ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"];
116
- }
117
-
118
- if (browser === "chrome") {
119
- return ["/usr/bin/google-chrome", "/usr/bin/google-chrome-stable"];
120
- }
121
-
122
- return ["/usr/bin/chromium", "/snap/bin/chromium", "/usr/bin/microsoft-edge", "/usr/bin/google-chrome", "/usr/bin/google-chrome-stable"];
123
- }
124
-
125
- export function findChromePath({
126
- argv = process.argv.slice(2),
127
- env = process.env,
128
- exists = existsSync,
129
- platform = process.platform,
130
- rootDir = process.cwd(),
131
- } = {}) {
132
- const requestedBrowser = getRequestedBrowser(argv);
133
- const explicitChromePath = getArgValue(argv, "--chrome-path") || env.CHROME_FOR_TESTING_PATH;
134
- if (explicitChromePath?.trim()) {
135
- return explicitChromePath.trim();
136
- }
137
-
138
- const localChromeForTestingPath = findLocalChromeForTesting({ rootDir, platform, exists });
139
- if (localChromeForTestingPath) {
140
- return localChromeForTestingPath;
141
- }
142
-
143
- if (
144
- env.CHROME_PATH?.trim() &&
145
- (!requestedBrowser || isLikelyGoogleChromeOrChromeForTesting(env.CHROME_PATH.trim()))
146
- ) {
147
- return env.CHROME_PATH.trim();
148
- }
149
-
150
- const foundPath = candidateChromePaths({ browser: requestedBrowser, env, platform }).find((candidate) => exists(candidate));
151
- if (foundPath) {
152
- return foundPath;
153
- }
154
-
155
- throw new Error(
156
- "Chrome executable was not found. Set CHROME_PATH or pass --chrome-path=<path-to-chrome>.",
157
- );
158
- }
159
-
160
- export function isLikelyBrandedChrome(chromePath) {
161
- const normalizedPath = chromePath.toLowerCase().replaceAll("\\", "/");
162
-
163
- if (normalizedPath.includes("chrome for testing") || normalizedPath.includes("chrome-for-testing")) {
164
- return false;
165
- }
166
- if (normalizedPath.includes("chrome-win64") || normalizedPath.includes("chromium") || normalizedPath.includes("/microsoft/edge/")) {
167
- return false;
168
- }
169
-
170
- return normalizedPath.includes("/google/chrome/application/chrome.exe") || normalizedPath.endsWith("/google chrome");
171
- }
172
-
173
- export function buildChromeLaunchConfig({
174
- argv = process.argv.slice(2),
175
- env = process.env,
176
- existsSync: exists = existsSync,
177
- platform = process.platform,
178
- rootDir = process.cwd(),
179
- extensionRoot = getArgValue(argv, "--extension-root"),
180
- extensionName,
181
- extensionNames = extensionName ? [extensionName] : getRequestedExtensions(argv, rootDir),
182
- appUrl = getRequestedAppUrl(argv, env),
183
- profileDir = getProfileDirForExtensions(rootDir, extensionNames, extensionRoot),
184
- } = {}) {
185
- const launchExtensionDirs = getChromeLaunchExtensionDirs({ extensionNames, rootDir, extensionRoot });
186
- const launchExtensionArg = launchExtensionDirs.join(",");
187
- const url = getArgValue(argv, "--url") || appUrl;
188
- const chromePath = findChromePath({ argv, env, exists, platform, rootDir });
189
- const autoLoadSupported = argv.includes("--allow-branded-chrome") || !isLikelyBrandedChrome(chromePath);
190
- const baseArgs = [
191
- `--user-data-dir=${profileDir}`,
192
- "--new-window",
193
- "--no-first-run",
194
- "--no-default-browser-check",
195
- ];
196
-
197
- if (!autoLoadSupported) {
198
- return {
199
- autoLoadSupported,
200
- chromePath,
201
- launchExtensionDirs,
202
- args: [...baseArgs, chromeExtensionsUrl, url],
203
- manualLoadPath: launchExtensionDirs.join(", "),
204
- resetProfile: argv.includes("--reset-profile"),
205
- unsupportedAutoLoadReason:
206
- "Automatic unpacked extension loading is disabled in current branded Chrome builds. Use Chrome for Testing for one-command loading, or load the unpacked extension manually.",
207
- };
208
- }
209
-
210
- return {
211
- autoLoadSupported,
212
- chromePath,
213
- launchExtensionDirs,
214
- args: [
215
- ...baseArgs,
216
- `--load-extension=${launchExtensionArg}`,
217
- `--disable-extensions-except=${launchExtensionArg}`,
218
- chromeExtensionsUrl,
219
- url,
220
- ],
221
- resetProfile: argv.includes("--reset-profile"),
222
- };
223
- }
224
-
225
- export function samePath(left, right) {
226
- const resolvedLeft = path.resolve(left);
227
- const resolvedRight = path.resolve(right);
228
- return process.platform === "win32"
229
- ? resolvedLeft.toLowerCase() === resolvedRight.toLowerCase()
230
- : resolvedLeft === resolvedRight;
231
- }
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync, readdirSync, statSync } from "node:fs";
3
+ import path from "node:path";
4
+ import { chromeExtensionsUrl, getArgValue, getChromeLaunchExtensionDirs, getProfileDirForExtensions, getProjectPaths, getRequestedAppUrl, getRequestedBrowser, getRequestedExtensions } from "./cli.mjs";
5
+
6
+ export function normalizeChromeExtensionPath(extensionPath, platform) {
7
+ const pathApi = platform === "win32" ? path.win32 : path.posix;
8
+ const resolvedPath = pathApi.resolve(extensionPath);
9
+
10
+ if (platform !== "win32") {
11
+ return resolvedPath;
12
+ }
13
+
14
+ return resolvedPath.replace(/^([a-z]):/, (_, driveLetter) => `${driveLetter.toUpperCase()}:`);
15
+ }
16
+
17
+ export function getChromeExtensionIdForPath(extensionPath, { platform = process.platform } = {}) {
18
+ const normalizedPath = normalizeChromeExtensionPath(extensionPath, platform);
19
+ const pathBytes = platform === "win32" ? Buffer.from(normalizedPath, "utf16le") : Buffer.from(normalizedPath);
20
+ const digest = createHash("sha256").update(pathBytes).digest("hex").slice(0, 32);
21
+
22
+ return digest.replace(/[0-9a-f]/g, (character) => "abcdefghijklmnop"[Number.parseInt(character, 16)]);
23
+ }
24
+
25
+ export function getChromeExecutableName(platform) {
26
+ if (platform === "win32") return "chrome.exe";
27
+ if (platform === "darwin") return "Google Chrome for Testing";
28
+ return "chrome";
29
+ }
30
+
31
+ export function findExecutableBelow(directory, executableName) {
32
+ const entries = readdirSync(directory, { withFileTypes: true });
33
+
34
+ for (const entry of entries) {
35
+ const entryPath = path.join(directory, entry.name);
36
+ if (entry.isFile() && entry.name === executableName) {
37
+ return entryPath;
38
+ }
39
+ if (entry.isDirectory()) {
40
+ const foundPath = findExecutableBelow(entryPath, executableName);
41
+ if (foundPath) return foundPath;
42
+ }
43
+ }
44
+
45
+ return null;
46
+ }
47
+
48
+ export function findLocalChromeForTesting({
49
+ rootDir = process.cwd(),
50
+ platform = process.platform,
51
+ exists = existsSync,
52
+ } = {}) {
53
+ const { chromeForTestingDir } = getProjectPaths(rootDir);
54
+ if (!exists(chromeForTestingDir)) {
55
+ return null;
56
+ }
57
+
58
+ try {
59
+ if (!statSync(chromeForTestingDir).isDirectory()) {
60
+ return null;
61
+ }
62
+ return findExecutableBelow(chromeForTestingDir, getChromeExecutableName(platform));
63
+ } catch (error) {
64
+ if (error?.code === "ENOENT") {
65
+ return null;
66
+ }
67
+ throw error;
68
+ }
69
+ }
70
+
71
+ export function isLikelyGoogleChromeOrChromeForTesting(chromePath) {
72
+ const normalizedPath = chromePath.toLowerCase().replaceAll("\\", "/");
73
+
74
+ return (
75
+ normalizedPath.includes("chrome for testing") ||
76
+ normalizedPath.includes("chrome-for-testing") ||
77
+ normalizedPath.includes("chrome-win64") ||
78
+ normalizedPath.includes("/google/chrome/application/chrome.exe") ||
79
+ normalizedPath.endsWith("/google chrome")
80
+ );
81
+ }
82
+
83
+ export function candidateChromePaths({ browser, env, platform }) {
84
+ if (platform === "win32") {
85
+ if (browser === "chrome") {
86
+ return [
87
+ env.CHROME_FOR_TESTING_PATH,
88
+ env.LOCALAPPDATA && path.join(env.LOCALAPPDATA, "Google", "Chrome", "Application", "chrome.exe"),
89
+ env.PROGRAMFILES && path.join(env.PROGRAMFILES, "Google", "Chrome", "Application", "chrome.exe"),
90
+ env["PROGRAMFILES(X86)"] && path.join(env["PROGRAMFILES(X86)"], "Google", "Chrome", "Application", "chrome.exe"),
91
+ String.raw`C:\Program Files\Google\Chrome\Application\chrome.exe`,
92
+ String.raw`C:\Program Files (x86)\Google\Chrome\Application\chrome.exe`,
93
+ ].filter(Boolean);
94
+ }
95
+
96
+ return [
97
+ env.CHROME_FOR_TESTING_PATH,
98
+ env.LOCALAPPDATA && path.join(env.LOCALAPPDATA, "Chromium", "Application", "chrome.exe"),
99
+ env.PROGRAMFILES && path.join(env.PROGRAMFILES, "Chromium", "Application", "chrome.exe"),
100
+ env["PROGRAMFILES(X86)"] && path.join(env["PROGRAMFILES(X86)"], "Chromium", "Application", "chrome.exe"),
101
+ env.LOCALAPPDATA && path.join(env.LOCALAPPDATA, "Microsoft", "Edge", "Application", "msedge.exe"),
102
+ env.PROGRAMFILES && path.join(env.PROGRAMFILES, "Microsoft", "Edge", "Application", "msedge.exe"),
103
+ env["PROGRAMFILES(X86)"] && path.join(env["PROGRAMFILES(X86)"], "Microsoft", "Edge", "Application", "msedge.exe"),
104
+ env.LOCALAPPDATA && path.join(env.LOCALAPPDATA, "Google", "Chrome", "Application", "chrome.exe"),
105
+ env.PROGRAMFILES && path.join(env.PROGRAMFILES, "Google", "Chrome", "Application", "chrome.exe"),
106
+ env["PROGRAMFILES(X86)"] && path.join(env["PROGRAMFILES(X86)"], "Google", "Chrome", "Application", "chrome.exe"),
107
+ String.raw`C:\Program Files\Microsoft\Edge\Application\msedge.exe`,
108
+ String.raw`C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe`,
109
+ String.raw`C:\Program Files\Google\Chrome\Application\chrome.exe`,
110
+ String.raw`C:\Program Files (x86)\Google\Chrome\Application\chrome.exe`,
111
+ ].filter(Boolean);
112
+ }
113
+
114
+ if (platform === "darwin") {
115
+ return ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"];
116
+ }
117
+
118
+ if (browser === "chrome") {
119
+ return ["/usr/bin/google-chrome", "/usr/bin/google-chrome-stable"];
120
+ }
121
+
122
+ return ["/usr/bin/chromium", "/snap/bin/chromium", "/usr/bin/microsoft-edge", "/usr/bin/google-chrome", "/usr/bin/google-chrome-stable"];
123
+ }
124
+
125
+ export function findChromePath({
126
+ argv = process.argv.slice(2),
127
+ env = process.env,
128
+ exists = existsSync,
129
+ platform = process.platform,
130
+ rootDir = process.cwd(),
131
+ } = {}) {
132
+ const requestedBrowser = getRequestedBrowser(argv);
133
+ const explicitChromePath = getArgValue(argv, "--chrome-path") || env.CHROME_FOR_TESTING_PATH;
134
+ if (explicitChromePath?.trim()) {
135
+ return explicitChromePath.trim();
136
+ }
137
+
138
+ const localChromeForTestingPath = findLocalChromeForTesting({ rootDir, platform, exists });
139
+ if (localChromeForTestingPath) {
140
+ return localChromeForTestingPath;
141
+ }
142
+
143
+ if (
144
+ env.CHROME_PATH?.trim() &&
145
+ (!requestedBrowser || isLikelyGoogleChromeOrChromeForTesting(env.CHROME_PATH.trim()))
146
+ ) {
147
+ return env.CHROME_PATH.trim();
148
+ }
149
+
150
+ const foundPath = candidateChromePaths({ browser: requestedBrowser, env, platform }).find((candidate) => exists(candidate));
151
+ if (foundPath) {
152
+ return foundPath;
153
+ }
154
+
155
+ throw new Error(
156
+ "Chrome executable was not found. Set CHROME_PATH or pass --chrome-path=<path-to-chrome>.",
157
+ );
158
+ }
159
+
160
+ export function isLikelyBrandedChrome(chromePath) {
161
+ const normalizedPath = chromePath.toLowerCase().replaceAll("\\", "/");
162
+
163
+ if (normalizedPath.includes("chrome for testing") || normalizedPath.includes("chrome-for-testing")) {
164
+ return false;
165
+ }
166
+ if (normalizedPath.includes("chrome-win64") || normalizedPath.includes("chromium") || normalizedPath.includes("/microsoft/edge/")) {
167
+ return false;
168
+ }
169
+
170
+ return normalizedPath.includes("/google/chrome/application/chrome.exe") || normalizedPath.endsWith("/google chrome");
171
+ }
172
+
173
+ export function buildChromeLaunchConfig({
174
+ argv = process.argv.slice(2),
175
+ env = process.env,
176
+ existsSync: exists = existsSync,
177
+ platform = process.platform,
178
+ rootDir = process.cwd(),
179
+ extensionRoot = getArgValue(argv, "--extension-root"),
180
+ extensionName,
181
+ extensionNames = extensionName ? [extensionName] : getRequestedExtensions(argv, rootDir),
182
+ appUrl = getRequestedAppUrl(argv, env),
183
+ profileDir = getProfileDirForExtensions(rootDir, extensionNames, extensionRoot),
184
+ } = {}) {
185
+ const launchExtensionDirs = getChromeLaunchExtensionDirs({ extensionNames, rootDir, extensionRoot });
186
+ const launchExtensionArg = launchExtensionDirs.join(",");
187
+ const url = getArgValue(argv, "--url") || appUrl;
188
+ const chromePath = findChromePath({ argv, env, exists, platform, rootDir });
189
+ const autoLoadSupported = argv.includes("--allow-branded-chrome") || !isLikelyBrandedChrome(chromePath);
190
+ const baseArgs = [
191
+ `--user-data-dir=${profileDir}`,
192
+ "--new-window",
193
+ "--no-first-run",
194
+ "--no-default-browser-check",
195
+ ];
196
+
197
+ if (!autoLoadSupported) {
198
+ return {
199
+ autoLoadSupported,
200
+ chromePath,
201
+ launchExtensionDirs,
202
+ args: [...baseArgs, chromeExtensionsUrl, url],
203
+ manualLoadPath: launchExtensionDirs.join(", "),
204
+ resetProfile: argv.includes("--reset-profile"),
205
+ unsupportedAutoLoadReason:
206
+ "Automatic unpacked extension loading is disabled in current branded Chrome builds. Use Chrome for Testing for one-command loading, or load the unpacked extension manually.",
207
+ };
208
+ }
209
+
210
+ return {
211
+ autoLoadSupported,
212
+ chromePath,
213
+ launchExtensionDirs,
214
+ args: [
215
+ ...baseArgs,
216
+ `--load-extension=${launchExtensionArg}`,
217
+ `--disable-extensions-except=${launchExtensionArg}`,
218
+ chromeExtensionsUrl,
219
+ url,
220
+ ],
221
+ resetProfile: argv.includes("--reset-profile"),
222
+ };
223
+ }
224
+
225
+ export function samePath(left, right) {
226
+ const resolvedLeft = path.resolve(left);
227
+ const resolvedRight = path.resolve(right);
228
+ return process.platform === "win32"
229
+ ? resolvedLeft.toLowerCase() === resolvedRight.toLowerCase()
230
+ : resolvedLeft === resolvedRight;
231
+ }