webhelm 1.0.3 → 1.0.4
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.
- package/package.json +1 -1
- package/runtime/chrome.mjs +19 -4
package/package.json
CHANGED
package/runtime/chrome.mjs
CHANGED
|
@@ -91,6 +91,24 @@ async function lockOwnership(fn) {
|
|
|
91
91
|
try {return await fn();}
|
|
92
92
|
finally {fs.closeSync(fd);try {fs.unlinkSync(LOCK);}catch{}}
|
|
93
93
|
}
|
|
94
|
+
export function chromeMajorFromVersion(versionText){
|
|
95
|
+
const match=String(versionText).match(/(?:Chrome|Chromium)\s+(?:for Testing\s+)?(\d+)\./);
|
|
96
|
+
const major=match?Number(match[1]):NaN;
|
|
97
|
+
if(!Number.isSafeInteger(major)||major<50)throw Error(`Cannot determine managed Chrome version: ${versionText}`);
|
|
98
|
+
return major;
|
|
99
|
+
}
|
|
100
|
+
function chromeMajor(chromePath){
|
|
101
|
+
return chromeMajorFromVersion(execFileSync(chromePath,['--version'],{encoding:'utf8',timeout:5000}).trim());
|
|
102
|
+
}
|
|
103
|
+
export function chromeLaunchArgs(profile,port,extensionPath,major){
|
|
104
|
+
const args=[`--user-data-dir=${profile}`,`--remote-debugging-port=${port}`];
|
|
105
|
+
// Chrome 138 can load unpacked extensions with a compatibility flag.
|
|
106
|
+
// Chrome 139+ must rely on Extensions.loadUnpacked through CDP instead:
|
|
107
|
+
// passing --load-extension can leave a stale, non-running extension entry.
|
|
108
|
+
if(major<=138)args.push('--disable-features=DisableLoadExtensionCommandLineSwitch',`--load-extension=${extensionPath}`);
|
|
109
|
+
args.push('--no-first-run','--no-default-browser-check','about:blank');
|
|
110
|
+
return args;
|
|
111
|
+
}
|
|
94
112
|
export async function ensureManagedChrome(){
|
|
95
113
|
// Explicit CDP endpoints also support hermetic mock-browser tests.
|
|
96
114
|
const specified=process.env.WEBHELM_CDP_URL;
|
|
@@ -107,10 +125,7 @@ export async function ensureManagedChrome(){
|
|
|
107
125
|
const extension=stageExtension();
|
|
108
126
|
const log=fs.openSync(path.join(ROOT,'managed-chrome.log'),'a');
|
|
109
127
|
fs.mkdirSync(PROFILE,{recursive:true});
|
|
110
|
-
const child=spawn(chrome,
|
|
111
|
-
'--disable-features=DisableLoadExtensionCommandLineSwitch',
|
|
112
|
-
`--load-extension=${extension.path}`,
|
|
113
|
-
'--no-first-run','--no-default-browser-check','about:blank'],
|
|
128
|
+
const child=spawn(chrome,chromeLaunchArgs(PROFILE,port,extension.path,chromeMajor(chrome)),
|
|
114
129
|
{detached:true,stdio:['ignore',log,log]});
|
|
115
130
|
child.unref();
|
|
116
131
|
fs.closeSync(log);
|