webhelm 1.0.58 → 1.0.60
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 +24 -7
- package/runtime/cli-help.mjs +2 -1
- package/runtime/extension/manifest.json +1 -1
- package/runtime/webmcp.mjs +12 -1
package/package.json
CHANGED
package/runtime/chrome.mjs
CHANGED
|
@@ -106,8 +106,22 @@ export function chromeMajorFromVersion(versionText){
|
|
|
106
106
|
if(!Number.isSafeInteger(major)||major<50)throw Error(`Cannot determine managed Chrome version: ${versionText}`);
|
|
107
107
|
return major;
|
|
108
108
|
}
|
|
109
|
-
function chromeMajor(chromePath){
|
|
110
|
-
|
|
109
|
+
export function chromeMajor(chromePath,{platform=process.platform,exec=execFileSync,realpath=fs.realpathSync}={}){
|
|
110
|
+
const options={encoding:'utf8',timeout:5000};
|
|
111
|
+
if(platform==='darwin'){
|
|
112
|
+
// Launching Chrome --version can initialize its Framework and crash during
|
|
113
|
+
// an application auto-update. Read the selected bundle instead, including
|
|
114
|
+
// symlinked custom executable paths. Never spawn Chrome as a fallback.
|
|
115
|
+
const executable=realpath(chromePath);
|
|
116
|
+
const contents=path.dirname(path.dirname(executable));
|
|
117
|
+
if(path.basename(path.dirname(executable))!=='MacOS'||path.basename(contents)!=='Contents'||!path.dirname(contents).endsWith('.app'))
|
|
118
|
+
throw Error('Managed Chrome executable must be inside a macOS application bundle');
|
|
119
|
+
const plist=path.join(contents,'Info.plist');
|
|
120
|
+
const version=exec('/usr/libexec/PlistBuddy',['-c','Print :CFBundleShortVersionString',plist],options).trim();
|
|
121
|
+
if(!/^\d+(?:\.\d+)+$/.test(version))throw Error('Cannot determine managed Chrome bundle version');
|
|
122
|
+
return chromeMajorFromVersion('Chrome '+version);
|
|
123
|
+
}
|
|
124
|
+
return chromeMajorFromVersion(exec(chromePath,['--version'],options).trim());
|
|
111
125
|
}
|
|
112
126
|
export function chromeLaunchArgs(profile,port,extensionPath,major){
|
|
113
127
|
const args=[`--user-data-dir=${profile}`,`--remote-debugging-port=${port}`,'--enable-features=WebMCP'];
|
|
@@ -131,13 +145,16 @@ export async function ensureManagedChrome(){
|
|
|
131
145
|
if(override)return {mode:'override',reused:true,endpoint:override,profile_dir:PROFILE};
|
|
132
146
|
const port=await choosePort();
|
|
133
147
|
const chrome=browserExecutable();
|
|
148
|
+
const major=chromeMajor(chrome);
|
|
134
149
|
const extension=stageExtension();
|
|
135
|
-
const log=fs.openSync(path.join(ROOT,'managed-chrome.log'),'a');
|
|
136
150
|
fs.mkdirSync(PROFILE,{recursive:true});
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
151
|
+
const log=fs.openSync(path.join(ROOT,'managed-chrome.log'),'a');
|
|
152
|
+
let child;
|
|
153
|
+
try{
|
|
154
|
+
child=spawn(chrome,chromeLaunchArgs(PROFILE,port,extension.path,major),
|
|
155
|
+
{detached:true,stdio:['ignore',log,log]});
|
|
156
|
+
child.unref();
|
|
157
|
+
}finally{fs.closeSync(log);}
|
|
141
158
|
for(let tries=0;tries<100;tries++){
|
|
142
159
|
if(await endpointLive(port)){
|
|
143
160
|
const state={chrome_path:chrome,pid:child.pid,port,profile_dir:PROFILE};
|
package/runtime/cli-help.mjs
CHANGED
|
@@ -275,7 +275,8 @@ Options:
|
|
|
275
275
|
Lists tools registered in the selected main frame of an existing CLI-owned
|
|
276
276
|
Session. Does not navigate or invoke tools. Output: JSON with session_id,
|
|
277
277
|
target_id and tools (names, descriptions, input schemas and annotations).
|
|
278
|
-
An empty tools array means no tools were discovered
|
|
278
|
+
An empty tools array means no tools were discovered or Chrome does not
|
|
279
|
+
support WebMCP. Other unavailable discovery
|
|
279
280
|
exits nonzero.
|
|
280
281
|
|
|
281
282
|
Example:
|
package/runtime/webmcp.mjs
CHANGED
|
@@ -91,7 +91,18 @@ async function withWebMCP(browser, sessionId, {name,input,discovery_ms,timeout_m
|
|
|
91
91
|
});
|
|
92
92
|
// Subscribe before enabling: Chrome sends existing registrations as events.
|
|
93
93
|
enabled=true;
|
|
94
|
-
|
|
94
|
+
try {
|
|
95
|
+
await browser.send('WebMCP.enable',{},sessionId);
|
|
96
|
+
} catch(error) {
|
|
97
|
+
// Older Chrome reports an absent CDP domain as method not found.
|
|
98
|
+
// Do not disguise transport failures or revoked ownership as no tools.
|
|
99
|
+
const unsupported=/unknown (?:domain|method|command)|(?:method|command).*not found|(?:WebMCP\.enable).*wasn't found|not supported/i.test(error?.message||'');
|
|
100
|
+
if(unsupported){
|
|
101
|
+
enabled=false;
|
|
102
|
+
return name===undefined&&active()&&!invalidated?[]:null;
|
|
103
|
+
}
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
95
106
|
async function waitUntil(condition,ms){
|
|
96
107
|
const end=Date.now()+ms;
|
|
97
108
|
while(active()&&!invalidated&&!condition()&&Date.now()<end){
|