gm-plugkit 2.0.1685 → 2.0.1687
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/plugkit-wasm-wrapper.js +30 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gm-plugkit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1687",
|
|
4
4
|
"description": "Bootstrap and daemon-spawn tool for gm plugkit binary. Downloads the correct platform binary, verifies SHA256, and starts the spool watcher daemon. Includes plugkit-wasm-wrapper for WASM-based spool watching.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
package/plugkit-wasm-wrapper.js
CHANGED
|
@@ -1164,6 +1164,29 @@ function fetchJsonSync(url, timeoutMs) {
|
|
|
1164
1164
|
try { return JSON.parse(r.stdout); } catch (_) { return null; }
|
|
1165
1165
|
}
|
|
1166
1166
|
|
|
1167
|
+
function closeExtraBlankTabs(port, keepWsEndpoint) {
|
|
1168
|
+
try {
|
|
1169
|
+
const targets = fetchJsonSync(`http://127.0.0.1:${port}/json/list`, 1500);
|
|
1170
|
+
if (!Array.isArray(targets)) return { closed: 0 };
|
|
1171
|
+
let closed = 0;
|
|
1172
|
+
for (const t of targets) {
|
|
1173
|
+
if (!t || t.type !== 'page') continue;
|
|
1174
|
+
if (t.webSocketDebuggerUrl === keepWsEndpoint) continue;
|
|
1175
|
+
if (t.url !== 'about:blank' && t.url !== '') continue;
|
|
1176
|
+
const r = spawnSync(process.execPath, ['-e', `
|
|
1177
|
+
const http = require('http');
|
|
1178
|
+
const req = http.get(${JSON.stringify(`http://127.0.0.1:${port}/json/close/${t.id}`)}, res => { res.resume(); res.on('end', () => process.exit(0)); });
|
|
1179
|
+
req.on('error', () => process.exit(1));
|
|
1180
|
+
req.setTimeout(1500, () => { req.destroy(); process.exit(1); });
|
|
1181
|
+
`], { timeout: 3000, windowsHide: true });
|
|
1182
|
+
if (r.status === 0) closed++;
|
|
1183
|
+
}
|
|
1184
|
+
return { closed };
|
|
1185
|
+
} catch (_) {
|
|
1186
|
+
return { closed: 0 };
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1167
1190
|
function startManagedBrowser(pw, profileDir) {
|
|
1168
1191
|
const headless = process.env.GM_BROWSER_HEADLESS === '1';
|
|
1169
1192
|
let browserBin = findInstalledChromiumBinary();
|
|
@@ -1391,13 +1414,15 @@ function getOrCreateBrowserSession(cwd, claudeSessionId, pw) {
|
|
|
1391
1414
|
}
|
|
1392
1415
|
return null;
|
|
1393
1416
|
})();
|
|
1394
|
-
let browserPid, port, wsEndpoint;
|
|
1417
|
+
let browserPid, port, wsEndpoint, freshLaunch;
|
|
1395
1418
|
if (aliveCdpForProfile) {
|
|
1396
1419
|
({ pid: browserPid, port, wsEndpoint } = aliveCdpForProfile);
|
|
1420
|
+
freshLaunch = false;
|
|
1397
1421
|
logEvent('plugkit', 'browser.reused-existing-chromium', { pid: browserPid, port, profileDir });
|
|
1398
1422
|
} else {
|
|
1399
1423
|
logEvent('plugkit', 'browser.start', { profileDir });
|
|
1400
1424
|
({ pid: browserPid, port, wsEndpoint } = startManagedBrowser(pw, profileDir));
|
|
1425
|
+
freshLaunch = true;
|
|
1401
1426
|
}
|
|
1402
1427
|
markLaunching(browserPid);
|
|
1403
1428
|
const r = runBrowserRunner(pw, ['session', 'new', '--direct', wsEndpoint], 30000, cwd, claudeSessionId);
|
|
@@ -1406,6 +1431,10 @@ function getOrCreateBrowserSession(cwd, claudeSessionId, pw) {
|
|
|
1406
1431
|
logEvent('plugkit', 'browser.launch-failed', { reason: 'session-attach-failed', pid: browserPid, port, error: errTxt });
|
|
1407
1432
|
throw new Error(`playwriter session new --direct failed: ${errTxt}`);
|
|
1408
1433
|
}
|
|
1434
|
+
if (freshLaunch) {
|
|
1435
|
+
const { closed } = closeExtraBlankTabs(port, wsEndpoint);
|
|
1436
|
+
if (closed > 0) logEvent('plugkit', 'browser.extra-blank-tabs-closed', { pid: browserPid, port, closed });
|
|
1437
|
+
}
|
|
1409
1438
|
const pwSessionId = parseSessionId(r.stdout || '');
|
|
1410
1439
|
if (!pwSessionId) {
|
|
1411
1440
|
logEvent('plugkit', 'browser.launch-failed', { reason: 'session-id-unparseable', stdout: r.stdout });
|