glidercli 0.3.14 → 0.3.17
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/bin/glider.js +85 -11
- package/lib/bexplore.js +39 -7
- package/package.json +2 -2
package/bin/glider.js
CHANGED
|
@@ -91,7 +91,6 @@ for (const cfgPath of BROWSER_CONFIG_PATHS) {
|
|
|
91
91
|
|
|
92
92
|
// Browsers registry - key → { name, path, processName }. Used when browser.json has "use": "<key>"
|
|
93
93
|
const BROWSERS_REGISTRY_PATHS = [
|
|
94
|
-
path.join(os.homedir(), '.cursor', 'registry', 'browsers.json'),
|
|
95
94
|
path.join(os.homedir(), '.glider', 'config', 'browsers-registry.json'),
|
|
96
95
|
].filter(Boolean);
|
|
97
96
|
let BROWSERS_REGISTRY = {};
|
|
@@ -502,11 +501,33 @@ async function cmdGoto(url) {
|
|
|
502
501
|
method: 'Page.navigate',
|
|
503
502
|
params: { url }
|
|
504
503
|
});
|
|
504
|
+
// v0.3.15: detect nav errors; auto-attach after successful goto.
|
|
505
|
+
// Prior code printed raw result THEN unconditionally logged '✓ Navigated' -
|
|
506
|
+
// even when result contained {"error":"Session not found"} (stale pinned session after reload-ext).
|
|
507
|
+
// Now: detect embedded error, don't lie about success, then auto-attach the target tab.
|
|
508
|
+
const hasErr = result && (result.error || (typeof result === 'string' && result.includes('error')));
|
|
505
509
|
if (jsonOutput) {
|
|
506
|
-
emitJson(
|
|
510
|
+
emitJson(!hasErr, { url, navigate: result }, hasErr ? (result.error?.message || result.error || 'unknown') : null);
|
|
511
|
+
} else if (hasErr) {
|
|
512
|
+
log.fail(`Navigation reported error: ${JSON.stringify(result)}`);
|
|
513
|
+
log.info(' hint: pinned session may be stale (e.g. after reload-ext). Try `glider attach-all` or unset GLIDER_SESSION_ID.');
|
|
507
514
|
} else {
|
|
508
|
-
console.log(JSON.stringify(result));
|
|
509
515
|
log.ok('Navigated');
|
|
516
|
+
// Auto-attach the tab we just navigated to (best-effort, non-fatal on failure).
|
|
517
|
+
// Uses URL host as substring filter so we don't accidentally re-attach unrelated tabs.
|
|
518
|
+
try {
|
|
519
|
+
const u = new URL(url);
|
|
520
|
+
const host = u.hostname;
|
|
521
|
+
// small delay lets the tab actually load + register in chrome.tabs before attach
|
|
522
|
+
await new Promise(x => setTimeout(x, 800));
|
|
523
|
+
const attach = await postExtension({ method: 'attachAllTabs', params: { urlSubstring: host } });
|
|
524
|
+
const d = attach.result ?? attach;
|
|
525
|
+
if ((d.attached ?? 0) > 0) {
|
|
526
|
+
log.info(` auto-attached ${d.attached} tab(s) matching host="${host}"`);
|
|
527
|
+
}
|
|
528
|
+
} catch (attErr) {
|
|
529
|
+
// silent: nav succeeded, auto-attach is a nice-to-have
|
|
530
|
+
}
|
|
510
531
|
}
|
|
511
532
|
} catch (e) {
|
|
512
533
|
if (jsonOutput) emitJson(false, null, e.message);
|
|
@@ -700,13 +721,14 @@ async function cmdRestart() {
|
|
|
700
721
|
await cmdStart();
|
|
701
722
|
}
|
|
702
723
|
|
|
703
|
-
//
|
|
704
|
-
|
|
705
|
-
// Bootstrap cost: one manual reload after installing this handler for the first time.
|
|
724
|
+
// reload-ext: automate extension reload + tab re-attachment so operators
|
|
725
|
+
***REMOVED***
|
|
706
726
|
async function cmdReloadExt() {
|
|
707
727
|
try {
|
|
708
728
|
const r = await postExtension({ method: 'reloadSelf', params: {} });
|
|
709
|
-
|
|
729
|
+
// v0.3.15: same response unwrap fix as attach-all - r.result was always undefined
|
|
730
|
+
const persisted = (r.result?.persisted ?? r.persisted ?? '?');
|
|
731
|
+
log.ok(`Extension reload triggered (persisted ${persisted} tab URLs).`);
|
|
710
732
|
log.info('Waiting 4s for extension to boot back up + reconnect...');
|
|
711
733
|
await new Promise(x => setTimeout(x, 4000));
|
|
712
734
|
// Extension reboots → autoAttachActiveTab restores from chrome.storage
|
|
@@ -722,7 +744,18 @@ async function cmdReloadExt() {
|
|
|
722
744
|
async function cmdAttachAll(filter) {
|
|
723
745
|
try {
|
|
724
746
|
const r = await postExtension({ method: 'attachAllTabs', params: filter ? { urlSubstring: filter } : {} });
|
|
725
|
-
|
|
747
|
+
// v0.3.15: attach-all response unwrap fix -
|
|
748
|
+
// relay's sendToExtension unwraps msg.result before HTTP POST responds, so relay body is {attached, skipped, failed, total_connected} bare.
|
|
749
|
+
// Prior code read r.result.attached which was always undefined → literal '?' placeholders on every attach-all.
|
|
750
|
+
const d = r.result ?? r;
|
|
751
|
+
const attached = d.attached ?? 0;
|
|
752
|
+
const skipped = d.skipped ?? 0;
|
|
753
|
+
const failed = d.failed ?? 0;
|
|
754
|
+
const total = d.total_connected ?? 0;
|
|
755
|
+
log.ok(`attach-all: attached=${attached} skipped=${skipped} failed=${failed} total_connected=${total}`);
|
|
756
|
+
if (filter && attached === 0 && total > 0) {
|
|
757
|
+
log.info(` hint: filter "${filter}" matched 0 new tabs. Try 'glider attach-all' with no filter, or check 'glider tabs' for URL substrings that would match.`);
|
|
758
|
+
}
|
|
726
759
|
} catch (e) {
|
|
727
760
|
log.fail(`attach-all failed: ${e.message}`);
|
|
728
761
|
}
|
|
@@ -960,7 +993,7 @@ function cmdBrowser() {
|
|
|
960
993
|
}
|
|
961
994
|
console.log('');
|
|
962
995
|
console.log('Source: ~/.glider/config/browser.json { "use": "<key>" } or { name, path } → default "Google Chrome"');
|
|
963
|
-
console.log('Registry: ~/.
|
|
996
|
+
console.log('Registry: ~/.glider/config/browsers-registry.json. Keys: ' + (Object.keys(BROWSERS_REGISTRY).join(', ') || '(none loaded)'));
|
|
964
997
|
console.log('See README.md#browsers for compatibility and examples.');
|
|
965
998
|
}
|
|
966
999
|
|
|
@@ -2210,7 +2243,29 @@ async function cmdUpdate() {
|
|
|
2210
2243
|
async function main() {
|
|
2211
2244
|
const args = parseGlobalFlags(process.argv.slice(2));
|
|
2212
2245
|
loadPersistedSession();
|
|
2213
|
-
|
|
2246
|
+
let cmd = args[0];
|
|
2247
|
+
|
|
2248
|
+
// v0.3.15: reload-ext command aliases -
|
|
2249
|
+
// Accept common natural-language variants + typos for high-frequency commands.
|
|
2250
|
+
// Rewrites args in place so downstream switch stays clean.
|
|
2251
|
+
const RELOAD_EXT_TWO_WORD = new Set([
|
|
2252
|
+
'ext-reload', 'ext reload',
|
|
2253
|
+
'reload-extension', 'reload extension',
|
|
2254
|
+
'reload-ext'
|
|
2255
|
+
]);
|
|
2256
|
+
const RELOAD_EXT_ALIASES = new Set(['rex', 'reloadext', 'reloadExt']);
|
|
2257
|
+
if (cmd === 'ext' && args[1] === 'reload') {
|
|
2258
|
+
cmd = 'reload-ext';
|
|
2259
|
+
args.splice(0, 2, 'reload-ext');
|
|
2260
|
+
} else if (cmd === 'reload' && (args[1] === 'ext' || args[1] === 'extension')) {
|
|
2261
|
+
cmd = 'reload-ext';
|
|
2262
|
+
args.splice(0, 2, 'reload-ext');
|
|
2263
|
+
} else if (RELOAD_EXT_ALIASES.has(cmd)) {
|
|
2264
|
+
cmd = 'reload-ext';
|
|
2265
|
+
args[0] = 'reload-ext';
|
|
2266
|
+
}
|
|
2267
|
+
// Typo suggest: if cmd looks like a common command with 1-2 char edit distance, hint it.
|
|
2268
|
+
// (Only checked in unknown-command branch below - this block just normalizes.)
|
|
2214
2269
|
|
|
2215
2270
|
if (!cmd || cmd === '--help' || cmd === '-h') {
|
|
2216
2271
|
showHelp();
|
|
@@ -2253,7 +2308,7 @@ async function main() {
|
|
|
2253
2308
|
await cmdReloadExt();
|
|
2254
2309
|
break;
|
|
2255
2310
|
case 'attach-all':
|
|
2256
|
-
await cmdAttachAll(args[1]); // optional URL substring filter, e.g. '
|
|
2311
|
+
await cmdAttachAll(args[1]); // optional URL substring filter, e.g. 'example.com'
|
|
2257
2312
|
break;
|
|
2258
2313
|
case 'install':
|
|
2259
2314
|
await cmdInstallDaemon();
|
|
@@ -2408,6 +2463,25 @@ async function main() {
|
|
|
2408
2463
|
break;
|
|
2409
2464
|
}
|
|
2410
2465
|
log.fail(`Unknown command: ${cmd}`);
|
|
2466
|
+
// v0.3.15: typo suggest (Levenshtein <=2) before dumping full help.
|
|
2467
|
+
const KNOWN_CMDS = ['status','start','stop','restart','reload-ext','attach-all','install','uninstall',
|
|
2468
|
+
'update','version','connect','browser','use','test','domains','resolve','goto','eval','click','type',
|
|
2469
|
+
'screenshot','snapshot','text','html','title','url','tabs','targets','use-session','fetch','spawn',
|
|
2470
|
+
'extract','explore','favicon','window','reg','run','loop','ralph'];
|
|
2471
|
+
function lev(a, b) {
|
|
2472
|
+
if (Math.abs(a.length - b.length) > 2) return 3;
|
|
2473
|
+
const m = Array.from({length: a.length+1}, () => new Array(b.length+1).fill(0));
|
|
2474
|
+
for (let i = 0; i <= a.length; i++) m[i][0] = i;
|
|
2475
|
+
for (let j = 0; j <= b.length; j++) m[0][j] = j;
|
|
2476
|
+
for (let i = 1; i <= a.length; i++) for (let j = 1; j <= b.length; j++) {
|
|
2477
|
+
m[i][j] = a[i-1] === b[j-1] ? m[i-1][j-1] : 1 + Math.min(m[i-1][j-1], m[i-1][j], m[i][j-1]);
|
|
2478
|
+
}
|
|
2479
|
+
return m[a.length][b.length];
|
|
2480
|
+
}
|
|
2481
|
+
const near = KNOWN_CMDS.map(k => [k, lev(cmd, k)]).filter(x => x[1] <= 2).sort((a,b) => a[1]-b[1]).slice(0, 3);
|
|
2482
|
+
if (near.length > 0) {
|
|
2483
|
+
log.info(` Did you mean: ${near.map(x => x[0]).join(', ')} ?`);
|
|
2484
|
+
}
|
|
2411
2485
|
showHelp();
|
|
2412
2486
|
process.exit(1);
|
|
2413
2487
|
}
|
package/lib/bexplore.js
CHANGED
|
@@ -576,12 +576,20 @@ class SiteExplorer {
|
|
|
576
576
|
// Initial screenshot
|
|
577
577
|
await this.screenshot('initial');
|
|
578
578
|
|
|
579
|
-
// Discover all elements
|
|
580
|
-
|
|
581
|
-
|
|
579
|
+
// Discover all elements (best-effort - heavy SPAs may throw during discovery;
|
|
580
|
+
// don't let a discovery failure abort HAR persistence)
|
|
581
|
+
let elements;
|
|
582
|
+
try {
|
|
583
|
+
elements = await this.discoverElements();
|
|
584
|
+
console.error(`[explore] Found: ${elements.tabs.length} tabs, ${elements.buttons.length} buttons, ${elements.links.length} links`);
|
|
585
|
+
} catch (e) {
|
|
586
|
+
console.error(`[explore] DOM discovery failed (${e.message}); skipping discovery, preserving HAR`);
|
|
587
|
+
elements = { tabs: [], buttons: [], links: [], forms: [], tables: [], dropdowns: [], checkboxes: [], modals: [], sidePanels: [] };
|
|
588
|
+
this.siteMap.discoveryError = e.message;
|
|
589
|
+
}
|
|
582
590
|
|
|
583
591
|
if (depth === 0) {
|
|
584
|
-
console.error('[explore] depth=0 passive
|
|
592
|
+
console.error('[explore] depth=0 passive - no clicks, scroll, or toggles');
|
|
585
593
|
} else {
|
|
586
594
|
// Click through tabs
|
|
587
595
|
for (const tab of elements.tabs.slice(0, depth)) {
|
|
@@ -648,8 +656,12 @@ class SiteExplorer {
|
|
|
648
656
|
}
|
|
649
657
|
}
|
|
650
658
|
|
|
651
|
-
// Final screenshot
|
|
652
|
-
|
|
659
|
+
// Final screenshot (best-effort)
|
|
660
|
+
try {
|
|
661
|
+
await this.screenshot('final');
|
|
662
|
+
} catch (e) {
|
|
663
|
+
console.error(`[explore] Final screenshot failed (${e.message}); continuing`);
|
|
664
|
+
}
|
|
653
665
|
|
|
654
666
|
return this.generateReport();
|
|
655
667
|
}
|
|
@@ -833,7 +845,7 @@ Options:
|
|
|
833
845
|
--session-id ID CDP session (e.g. session-6 from GET /targets)
|
|
834
846
|
--help Show this help
|
|
835
847
|
|
|
836
|
-
Depth 0 (passive): reload, discover DOM, screenshots, HAR
|
|
848
|
+
Depth 0 (passive): reload, discover DOM, screenshots, HAR - zero clicks.
|
|
837
849
|
Depth N>0: up to N tab/button/checkbox interactions per category.
|
|
838
850
|
|
|
839
851
|
The tool will:
|
|
@@ -905,6 +917,26 @@ Examples:
|
|
|
905
917
|
|
|
906
918
|
} catch (err) {
|
|
907
919
|
console.error('Error:', err.message);
|
|
920
|
+
// Salvage: even on catastrophic failure, save whatever HAR + partial report we have
|
|
921
|
+
try {
|
|
922
|
+
if (harFile && explorer.requests && explorer.requests.length > 0) {
|
|
923
|
+
explorer.saveHAR();
|
|
924
|
+
console.error(`[explore] HAR salvaged despite error (${explorer.requests.length} requests captured)`);
|
|
925
|
+
}
|
|
926
|
+
if (explorer.outputDir && fs.existsSync(explorer.outputDir)) {
|
|
927
|
+
const partialReport = {
|
|
928
|
+
error: err.message,
|
|
929
|
+
url: explorer.siteMap?.url || 'unknown',
|
|
930
|
+
requestsCaptured: explorer.requests?.length || 0,
|
|
931
|
+
responsesCaptured: explorer.responses?.length || 0,
|
|
932
|
+
partial: true
|
|
933
|
+
};
|
|
934
|
+
fs.writeFileSync(path.join(explorer.outputDir, 'report.json'), JSON.stringify(partialReport, null, 2));
|
|
935
|
+
console.error(`[explore] Partial report saved: ${explorer.outputDir}/report.json`);
|
|
936
|
+
}
|
|
937
|
+
} catch (salvageErr) {
|
|
938
|
+
console.error(`[explore] Salvage failed: ${salvageErr.message}`);
|
|
939
|
+
}
|
|
908
940
|
process.exit(1);
|
|
909
941
|
} finally {
|
|
910
942
|
explorer.close();
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glidercli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.17",
|
|
4
4
|
"description": "Browser automation CLI. Control Chrome from terminal via CDP, run YAML task files, autonomous loops until completion.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"glider": "bin/glider.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"test": "node bin/glider.js --help
|
|
10
|
+
"test": "node bin/glider.js --help"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
13
|
"browser",
|