barebrowse 0.22.0 → 0.23.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.
- package/CHANGELOG.md +18 -0
- package/README.md +1 -1
- package/barebrowse.context.md +1 -1
- package/mcp-server.js +7 -2
- package/package.json +1 -1
- package/src/daemon.js +2 -0
- package/src/firefox-page.js +1 -11
- package/src/index.js +2 -7
- package/src/output-clean.js +37 -0
- package/src/with-timeout.js +16 -0
- package/types/output-clean.d.ts +8 -0
- package/types/with-timeout.d.ts +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.23.0] - 2026-10-14
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **barebrowse cleans up its own old output files.** Snapshots, screenshots,
|
|
8
|
+
articles and logs piled up in `.barebrowse/` forever. Files older than 7 days
|
|
9
|
+
are now removed once at MCP server start and once at `barebrowse open`
|
|
10
|
+
(honours `--output-dir`). Only barebrowse's exact timestamped names match, so
|
|
11
|
+
`session.json`, `state-*.json` (saved logins) and your own files are never
|
|
12
|
+
touched.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- **An absurd `wait_for` timeout no longer resets the page.** A timeout above
|
|
17
|
+
`setTimeout`'s maximum made the outer deadline overflow and fire after about
|
|
18
|
+
1ms; the resulting transient "timed out" error then wiped the page. The
|
|
19
|
+
deadline is now capped at the maximum.
|
|
20
|
+
|
|
3
21
|
## [0.22.0] - 2026-10-14
|
|
4
22
|
|
|
5
23
|
### Added
|
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ barebrowse click 8 # Click element
|
|
|
50
50
|
barebrowse close # End session
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
Outputs go to `.barebrowse/` as files -- agents read them with their file tools, no token waste in tool responses.
|
|
53
|
+
Outputs go to `.barebrowse/` as files -- agents read them with their file tools, no token waste in tool responses. Output files older than 7 days are auto-removed at session start; saved state files (`state-*.json`) are kept.
|
|
54
54
|
|
|
55
55
|
**Teach your agent the commands** by installing the skill file (a markdown reference the agent reads as context). The CLI tool itself still needs `npm install barebrowse` -- the skill just teaches the agent how to use it.
|
|
56
56
|
|
package/barebrowse.context.md
CHANGED
|
@@ -246,7 +246,7 @@ Action tools (click, type, press, scroll, hover, goto, back, forward, reload, dr
|
|
|
246
246
|
|
|
247
247
|
## CLI session mode
|
|
248
248
|
|
|
249
|
-
For coding agents (Claude Code, Copilot, Cursor) and quick interactive testing. Commands output files to `.barebrowse/` -- agents read them with file tools, avoiding token waste in tool responses.
|
|
249
|
+
For coding agents (Claude Code, Copilot, Cursor) and quick interactive testing. Commands output files to `.barebrowse/` -- agents read them with file tools, avoiding token waste in tool responses. Output files older than 7 days are auto-removed at session start (CLI `open` and MCP startup); saved state files (`state-*.json`) are kept.
|
|
250
250
|
|
|
251
251
|
```bash
|
|
252
252
|
barebrowse open https://example.com # Start daemon + navigate
|
package/mcp-server.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import { browse, connect } from './src/index.js';
|
|
14
14
|
import { formatReadable } from './src/readable.js';
|
|
15
|
+
import { cleanOld } from './src/output-clean.js';
|
|
15
16
|
import { mkdirSync, writeFileSync, readFileSync } from 'node:fs';
|
|
16
17
|
import { join, dirname } from 'node:path';
|
|
17
18
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
@@ -131,6 +132,9 @@ function resetPage() {
|
|
|
131
132
|
if (p) p.close().catch(() => {});
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
// setTimeout's max delay; larger values overflow and fire after ~1ms.
|
|
136
|
+
const MAX_TIMER_MS = 2 ** 31 - 1;
|
|
137
|
+
|
|
134
138
|
// Idle TTL: a server can outlive its conversation by days, holding a browser
|
|
135
139
|
// (GBs) the whole time. After BAREBROWSE_IDLE_MINUTES (default 15, 0 = off)
|
|
136
140
|
// with no tools/call in flight, release it; the next call opens a fresh one.
|
|
@@ -142,7 +146,7 @@ function resetPage() {
|
|
|
142
146
|
* the page.
|
|
143
147
|
*/
|
|
144
148
|
export function waitForDeadline(timeout) {
|
|
145
|
-
return Math.max(TIMEOUTS.wait_for, (timeout || 30000) + 5000);
|
|
149
|
+
return Math.min(Math.max(TIMEOUTS.wait_for, (timeout || 30000) + 5000), MAX_TIMER_MS);
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
export function idleMs(raw) {
|
|
@@ -150,7 +154,7 @@ export function idleMs(raw) {
|
|
|
150
154
|
if (raw === undefined || String(raw).trim() === '') return DEFAULT;
|
|
151
155
|
const n = Number(raw);
|
|
152
156
|
if (!Number.isFinite(n) || n < 0) return DEFAULT;
|
|
153
|
-
return Math.min(n * 60_000,
|
|
157
|
+
return Math.min(n * 60_000, MAX_TIMER_MS);
|
|
154
158
|
}
|
|
155
159
|
const IDLE_MS = idleMs(process.env.BAREBROWSE_IDLE_MINUTES);
|
|
156
160
|
let _inflight = 0;
|
|
@@ -771,6 +775,7 @@ async function handleMessage(msg) {
|
|
|
771
775
|
// runStdio() explicitly. Tests import TIMEOUTS/TOOLS without calling it.
|
|
772
776
|
|
|
773
777
|
export function runStdio() {
|
|
778
|
+
cleanOld(OUTPUT_DIR);
|
|
774
779
|
// One-line startup banner to stderr (stderr because stdout is the JSON-RPC
|
|
775
780
|
// channel — must not contain non-JSON-RPC bytes). Captured by Claude Code's
|
|
776
781
|
// MCP log, makes "I added barebrowse twice and got the wrong one" issues
|
package/package.json
CHANGED
package/src/daemon.js
CHANGED
|
@@ -12,6 +12,7 @@ import { randomBytes, timingSafeEqual } from 'node:crypto';
|
|
|
12
12
|
import { join, resolve } from 'node:path';
|
|
13
13
|
import { connect } from './index.js';
|
|
14
14
|
import { formatReadable } from './readable.js';
|
|
15
|
+
import { cleanOld } from './output-clean.js';
|
|
15
16
|
|
|
16
17
|
/** Owner-only file write helper — daemon artifacts can hold authenticated content. */
|
|
17
18
|
function writeFilePrivate(path, data) {
|
|
@@ -210,6 +211,7 @@ export async function startDaemon(opts, outputDir, initialUrl) {
|
|
|
210
211
|
export async function runDaemon(opts, outputDir, initialUrl) {
|
|
211
212
|
const absDir = resolve(outputDir);
|
|
212
213
|
mkdirSync(absDir, { recursive: true, mode: 0o700 });
|
|
214
|
+
cleanOld(absDir);
|
|
213
215
|
|
|
214
216
|
// Per-session auth token. The daemon binds to loopback, but loopback is
|
|
215
217
|
// shared across local users — without a token any local user/process could
|
package/src/firefox-page.js
CHANGED
|
@@ -25,6 +25,7 @@ import { dismissConsentFirefox } from './consent-firefox.js';
|
|
|
25
25
|
import { waitForNetworkIdleBiDi } from './network-idle.js';
|
|
26
26
|
import { decideDialog, dialogLogEntry } from './dialog.js';
|
|
27
27
|
import { isChallengePage, countNodes } from './challenge.js';
|
|
28
|
+
import { withTimeout } from './with-timeout.js';
|
|
28
29
|
|
|
29
30
|
/** BiDi/WebDriver normalized key values for named keys (U+E000 block). */
|
|
30
31
|
const BIDI_KEYS = {
|
|
@@ -174,17 +175,6 @@ export async function createFirefoxPage(bidi, opts = {}) {
|
|
|
174
175
|
});
|
|
175
176
|
}
|
|
176
177
|
|
|
177
|
-
/**
|
|
178
|
-
* Reject if `p` doesn't settle within `ms`. BiDi commands have no built-in
|
|
179
|
-
* timeout, so a navigate/reload/traverse whose `wait:'complete'` never fires
|
|
180
|
-
* (a page that never loads) would otherwise hang the call forever.
|
|
181
|
-
*/
|
|
182
|
-
function withTimeout(p, ms, label) {
|
|
183
|
-
let timer;
|
|
184
|
-
const t = new Promise((_, rej) => { timer = setTimeout(() => rej(new Error(`${label} timed out after ${ms}ms`)), ms); });
|
|
185
|
-
return Promise.race([p, t]).finally(() => clearTimeout(timer));
|
|
186
|
-
}
|
|
187
|
-
|
|
188
178
|
// Download tracking, parity with the CDP `page.downloads` array. Firefox
|
|
189
179
|
// downloads land in `downloadDir` (a throwaway dir the caller sets via launch
|
|
190
180
|
// prefs — see connectFirefox / firefox.js), so `savedPath` is a real path the
|
package/src/index.js
CHANGED
|
@@ -25,6 +25,7 @@ import { resolveBlocklistPatterns } from './blocklist.js';
|
|
|
25
25
|
import { waitForNetworkIdle } from './network-idle.js';
|
|
26
26
|
import { decideDialog, dialogLogEntry } from './dialog.js';
|
|
27
27
|
import { isChallengePage } from './challenge.js';
|
|
28
|
+
import { withTimeout } from './with-timeout.js';
|
|
28
29
|
import { readable as extractReadable } from './readable.js';
|
|
29
30
|
import { assertNavigable, assertUploadAllowed } from './url-guard.js';
|
|
30
31
|
import { join as pathJoin } from 'node:path';
|
|
@@ -811,13 +812,7 @@ export async function connect(opts = {}) {
|
|
|
811
812
|
async close() {
|
|
812
813
|
// Polite tab close is best-effort and bounded: a dead or hung browser
|
|
813
814
|
// must not skip the hard cleanup below (the profile dir / process leak).
|
|
814
|
-
|
|
815
|
-
try {
|
|
816
|
-
await Promise.race([
|
|
817
|
-
cdp.send('Target.closeTarget', { targetId: page.targetId }),
|
|
818
|
-
new Promise((r) => { timer = setTimeout(r, 2500); }),
|
|
819
|
-
]);
|
|
820
|
-
} catch {} finally { clearTimeout(timer); }
|
|
815
|
+
try { await withTimeout(cdp.send('Target.closeTarget', { targetId: page.targetId }), 2500, 'close'); } catch {}
|
|
821
816
|
try { cdp.close(); } catch {}
|
|
822
817
|
try {
|
|
823
818
|
await cleanupBrowser(browser); // no-op in attach mode (process: null)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* output-clean.js -- Age-based cleanup of barebrowse's own output files.
|
|
3
|
+
*
|
|
4
|
+
* Matches only `<prefix>-<timestamp>.<ext>` files barebrowse itself writes.
|
|
5
|
+
* session.json, state-*.json (deliberate saved logins) and any other file are never touched.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { readdirSync, statSync, unlinkSync } from 'node:fs';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
|
|
11
|
+
// toISOString() with [:.] -> '-': YYYY-MM-DDTHH-MM-SS-mmmZ. Exact, so a user's own
|
|
12
|
+
// `screenshot-2026-01-01.png` in a shared --output-dir is never matched.
|
|
13
|
+
const STAMP = '\\d{4}-\\d{2}-\\d{2}T\\d{2}-\\d{2}-\\d{2}-\\d{3}Z';
|
|
14
|
+
const OURS = new RegExp(
|
|
15
|
+
`^(?:page-${STAMP}\\.(?:yml|pdf)|screenshot-${STAMP}\\.(?:png|jpeg|webp)|article-${STAMP}\\.txt|(?:console|network|dialogs)-${STAMP}\\.json)$`,
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Delete barebrowse output files older than `days` in `dir` (non-recursive).
|
|
20
|
+
* Never throws; a missing dir or any per-file error is ignored.
|
|
21
|
+
* @param {string} dir
|
|
22
|
+
* @param {number} [days]
|
|
23
|
+
* @param {number} [now] - epoch ms, injectable for tests
|
|
24
|
+
*/
|
|
25
|
+
export function cleanOld(dir, days = 7, now = Date.now()) {
|
|
26
|
+
try {
|
|
27
|
+
const cutoff = now - days * 86400000;
|
|
28
|
+
for (const name of readdirSync(dir)) {
|
|
29
|
+
if (!OURS.test(name)) continue;
|
|
30
|
+
try {
|
|
31
|
+
const path = join(dir, name);
|
|
32
|
+
const st = statSync(path);
|
|
33
|
+
if (st.isFile() && st.mtimeMs < cutoff) unlinkSync(path);
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
36
|
+
} catch {}
|
|
37
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reject if `p` doesn't settle within `ms`. BiDi commands have no built-in
|
|
3
|
+
* timeout, so a navigate/reload/traverse whose `wait:'complete'` never fires
|
|
4
|
+
* (a page that never loads) would otherwise hang the call forever. Also bounds
|
|
5
|
+
* the best-effort tab close on both engines.
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {Promise<T>} p
|
|
8
|
+
* @param {number} ms
|
|
9
|
+
* @param {string} label
|
|
10
|
+
* @returns {Promise<T>}
|
|
11
|
+
*/
|
|
12
|
+
export function withTimeout(p, ms, label) {
|
|
13
|
+
let timer;
|
|
14
|
+
const t = new Promise((_, rej) => { timer = setTimeout(() => rej(new Error(`${label} timed out after ${ms}ms`)), ms); });
|
|
15
|
+
return Promise.race([p, t]).finally(() => clearTimeout(timer));
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delete barebrowse output files older than `days` in `dir` (non-recursive).
|
|
3
|
+
* Never throws; a missing dir or any per-file error is ignored.
|
|
4
|
+
* @param {string} dir
|
|
5
|
+
* @param {number} [days]
|
|
6
|
+
* @param {number} [now] - epoch ms, injectable for tests
|
|
7
|
+
*/
|
|
8
|
+
export function cleanOld(dir: string, days?: number, now?: number): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reject if `p` doesn't settle within `ms`. BiDi commands have no built-in
|
|
3
|
+
* timeout, so a navigate/reload/traverse whose `wait:'complete'` never fires
|
|
4
|
+
* (a page that never loads) would otherwise hang the call forever. Also bounds
|
|
5
|
+
* the best-effort tab close on both engines.
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {Promise<T>} p
|
|
8
|
+
* @param {number} ms
|
|
9
|
+
* @param {string} label
|
|
10
|
+
* @returns {Promise<T>}
|
|
11
|
+
*/
|
|
12
|
+
export function withTimeout<T>(p: Promise<T>, ms: number, label: string): Promise<T>;
|