sbuilder-mcp 0.100.3 → 0.100.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/CHANGELOG.md +6 -0
- package/CHANGELOG.vi.md +6 -0
- package/dist/vision/capture.js +21 -12
- package/dist/vision/imagediff.js +3 -1
- package/dist/vision/shoot.js +114 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,12 @@ All notable changes to this project are documented in this file.
|
|
|
6
6
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
7
7
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
8
8
|
|
|
9
|
+
## [0.100.4] - 2026-10-29
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- `sb_look` and `sb_import` no longer wait indefinitely on a hung Chrome: launching a browser or opening a tab times out after 15 seconds, and the stalled Chrome is replaced and retried once before an error is reported.
|
|
13
|
+
- Closing the browser after `sb_look` or `sb_import` waits at most 3 seconds and then kills the Chrome process group, so a busy machine no longer adds 10–24 seconds after the result is ready.
|
|
14
|
+
|
|
9
15
|
## [0.100.3] - 2026-10-29
|
|
10
16
|
|
|
11
17
|
### Changed
|
package/CHANGELOG.vi.md
CHANGED
|
@@ -6,6 +6,12 @@ Mọi thay đổi đáng chú ý của dự án được ghi lại trong file n
|
|
|
6
6
|
Định dạng dựa trên [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
7
7
|
và dự án tuân theo [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
8
8
|
|
|
9
|
+
## [0.100.4] - 2026-10-29
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- `sb_look` và `sb_import` không còn chờ vô hạn một Chrome bị treo: mở trình duyệt hoặc mở tab có hạn 15 giây, Chrome kẹt được thay mới và thử lại một lần trước khi báo lỗi.
|
|
13
|
+
- Việc đóng trình duyệt sau `sb_look` hoặc `sb_import` chỉ chờ tối đa 3 giây rồi kết thúc cưỡng bức process group của Chrome, nên máy bận không còn bị chậm thêm 10–24 giây sau khi đã có kết quả.
|
|
14
|
+
|
|
9
15
|
## [0.100.3] - 2026-10-29
|
|
10
16
|
|
|
11
17
|
### Changed
|
package/dist/vision/capture.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { settleDom } from './shoot.js';
|
|
1
|
+
import { ChromeStalled, deadline, launchChrome, release, settleDom } from './shoot.js';
|
|
3
2
|
/**
|
|
4
3
|
* The in-page walk, as a string the browser evaluates.
|
|
5
4
|
*
|
|
@@ -1378,15 +1377,13 @@ function capturePage(limits) {
|
|
|
1378
1377
|
async function withBrowser(fn) {
|
|
1379
1378
|
let browser;
|
|
1380
1379
|
try {
|
|
1381
|
-
//
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
handleSIGINT: false,
|
|
1385
|
-
handleSIGTERM: false,
|
|
1386
|
-
handleSIGHUP: false,
|
|
1387
|
-
});
|
|
1380
|
+
// shoot.ts's launcher (no Playwright signal handlers — `src/index.ts` owns
|
|
1381
|
+
// them), but a FRESH Chrome, never the pool, and bounded by `deadline`.
|
|
1382
|
+
browser = await launchChrome();
|
|
1388
1383
|
}
|
|
1389
1384
|
catch (e) {
|
|
1385
|
+
if (e instanceof ChromeStalled)
|
|
1386
|
+
throw e;
|
|
1390
1387
|
throw new Error('sbuilder: could not start Chrome to read that page. This server uses the SYSTEM ' +
|
|
1391
1388
|
`browser (playwright-core, channel "chrome") and did not find one: ${e.message}`);
|
|
1392
1389
|
}
|
|
@@ -1394,7 +1391,9 @@ async function withBrowser(fn) {
|
|
|
1394
1391
|
return await fn(browser);
|
|
1395
1392
|
}
|
|
1396
1393
|
finally {
|
|
1397
|
-
|
|
1394
|
+
// `release`, not `close`: the result is already in hand, and a busy machine
|
|
1395
|
+
// made the close alone cost 10-24s (see `release` in shoot.ts).
|
|
1396
|
+
await release(browser);
|
|
1398
1397
|
}
|
|
1399
1398
|
}
|
|
1400
1399
|
/**
|
|
@@ -1423,7 +1422,7 @@ const NAV_TIMEOUT_MS = 30_000;
|
|
|
1423
1422
|
async function readPage(browser, url, width, work, navMs = NAV_TIMEOUT_MS, settleMs) {
|
|
1424
1423
|
let page;
|
|
1425
1424
|
try {
|
|
1426
|
-
page = await browser.newPage({ viewport: { width, height: 900 } });
|
|
1425
|
+
page = await deadline(browser.newPage({ viewport: { width, height: 900 } }), 'open a tab');
|
|
1427
1426
|
// `domcontentloaded`, NOT `load`, and `settleDom` does the rest.
|
|
1428
1427
|
//
|
|
1429
1428
|
// `load` waits for every SUBRESOURCE — including third-party iframes, which
|
|
@@ -1496,7 +1495,14 @@ function readFailure(e) {
|
|
|
1496
1495
|
/** Open a URL and capture it. */
|
|
1497
1496
|
export async function capture(url, opts = {}) {
|
|
1498
1497
|
const limits = limitsFrom(opts);
|
|
1499
|
-
|
|
1498
|
+
const read = () => withBrowser((browser) => readPage(browser, url, opts.width ?? 1440, (page) => page.evaluate(capturePage, limits), opts.navTimeoutMs, opts.settleMs));
|
|
1499
|
+
// A wedged Chrome (see `deadline` in shoot.ts) is released by `withBrowser`;
|
|
1500
|
+
// a fresh one reads the page once more.
|
|
1501
|
+
return read().catch((e) => {
|
|
1502
|
+
if (e instanceof ChromeStalled)
|
|
1503
|
+
return read();
|
|
1504
|
+
throw e;
|
|
1505
|
+
});
|
|
1500
1506
|
}
|
|
1501
1507
|
/**
|
|
1502
1508
|
* Capture several pages through one browser.
|
|
@@ -1517,6 +1523,9 @@ export async function captureMany(urls, opts = {}) {
|
|
|
1517
1523
|
out.push({ url, ok: true, result });
|
|
1518
1524
|
}
|
|
1519
1525
|
catch (e) {
|
|
1526
|
+
// ponytail: a wedged Chrome (`ChromeStalled`) fails this page AND each later
|
|
1527
|
+
// one after its own 15s deadline, rather than hanging the run; relaunch
|
|
1528
|
+
// mid-loop if a site import is ever seen doing that.
|
|
1520
1529
|
out.push({ url, ok: false, why: readFailure(e) });
|
|
1521
1530
|
}
|
|
1522
1531
|
}
|
package/dist/vision/imagediff.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chromium } from 'playwright-core';
|
|
2
|
+
import { release } from './shoot.js';
|
|
2
3
|
/**
|
|
3
4
|
* ITS OWN BROWSER, not `shoot.ts`'s pooled one.
|
|
4
5
|
*
|
|
@@ -18,7 +19,8 @@ async function browser() {
|
|
|
18
19
|
export async function closeDiffBrowser() {
|
|
19
20
|
const b = shared;
|
|
20
21
|
shared = null;
|
|
21
|
-
|
|
22
|
+
if (b)
|
|
23
|
+
await release(b);
|
|
22
24
|
}
|
|
23
25
|
export async function diffImages(a, b, opts = {}) {
|
|
24
26
|
const width = opts.width ?? 480;
|
package/dist/vision/shoot.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
1
2
|
import { chromium } from 'playwright-core';
|
|
2
3
|
/** The three widths the platform's own breakpoints care about. */
|
|
3
4
|
export const DEFAULT_WIDTHS = [1440, 768, 390];
|
|
@@ -21,9 +22,11 @@ const JPEG_QUALITY = 80;
|
|
|
21
22
|
*/
|
|
22
23
|
async function launch() {
|
|
23
24
|
try {
|
|
24
|
-
return await
|
|
25
|
+
return await launchChrome();
|
|
25
26
|
}
|
|
26
27
|
catch (err) {
|
|
28
|
+
if (err instanceof ChromeStalled)
|
|
29
|
+
throw err;
|
|
27
30
|
throw new Error('sbuilder: could not launch Google Chrome for the screenshot. sb_look needs Chrome ' +
|
|
28
31
|
`installed — playwright-core bundles no browser. Underlying error: ${String(err)}`);
|
|
29
32
|
}
|
|
@@ -50,6 +53,46 @@ let launcher = realLauncher;
|
|
|
50
53
|
export function setLauncherForTest(fn) {
|
|
51
54
|
launcher = fn ?? realLauncher;
|
|
52
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* A FRESH Chrome — not the pool — bounded by `deadline`, its pid noted while it
|
|
58
|
+
* still answers. `capture.ts` launches through this too, so one launcher (and
|
|
59
|
+
* one test seam) serves both, while each keeps a browser of its own.
|
|
60
|
+
*/
|
|
61
|
+
export async function launchChrome() {
|
|
62
|
+
const b = await deadline(launcher(), 'start');
|
|
63
|
+
void pidOf(b);
|
|
64
|
+
return b;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A CHROME STEP THAT NEVER ANSWERS MEANS A WEDGED CHROME, and nothing else bounds it.
|
|
68
|
+
*
|
|
69
|
+
* MEASURED in the full browser suite on a busy machine: a `launch` that never
|
|
70
|
+
* returned, and a `newPage` that never answered — not one stderr line from that
|
|
71
|
+
* Chrome afterwards — while a fresh Chrome a moment later answered at once.
|
|
72
|
+
* `newPage` takes no timeout and `launch` defaults to 180s, so the caller simply
|
|
73
|
+
* hung: a test to its 60s limit, the pool's every later shot behind the same
|
|
74
|
+
* handle, and in the server every later tool call, because calls run one at a
|
|
75
|
+
* time. Healthy, the same steps took ≤3.7s at a load average of 47; the deadline
|
|
76
|
+
* is four times that, and missing it costs a relaunch, not a failure.
|
|
77
|
+
*/
|
|
78
|
+
let stallMs = 15_000;
|
|
79
|
+
/** Tests only: shorten the stall deadline. Pass nothing to restore it. */
|
|
80
|
+
export function setStallForTest(ms = 15_000) {
|
|
81
|
+
stallMs = ms;
|
|
82
|
+
}
|
|
83
|
+
export class ChromeStalled extends Error {
|
|
84
|
+
}
|
|
85
|
+
/** `step`, or `ChromeStalled` once it has not answered for `ms`. */
|
|
86
|
+
export function deadline(step, what, ms = stallMs) {
|
|
87
|
+
return Promise.race([
|
|
88
|
+
step,
|
|
89
|
+
// `ref: false`: a pending deadline never keeps a finished process alive.
|
|
90
|
+
sleep(ms, undefined, { ref: false }).then(() => {
|
|
91
|
+
throw new ChromeStalled(`sbuilder: Chrome did not ${what} within ${ms / 1000}s. A busy machine can wedge one, ` +
|
|
92
|
+
'and a fresh one usually answers at once: repeat the call.');
|
|
93
|
+
}),
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
53
96
|
/**
|
|
54
97
|
* ONE Chrome per process, launched on first use and kept.
|
|
55
98
|
*
|
|
@@ -87,7 +130,63 @@ export async function closeBrowser() {
|
|
|
87
130
|
return;
|
|
88
131
|
const b = await p.catch(() => undefined);
|
|
89
132
|
if (b)
|
|
90
|
-
await b
|
|
133
|
+
await release(b);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The OS pid of a launched Chrome, asked ONCE and kept — ideally right after the
|
|
137
|
+
* launch, while it still answers; the one that needs killing is the one that has
|
|
138
|
+
* stopped answering. `launch()` has no `browser.process()`, and CDP's
|
|
139
|
+
* `SystemInfo.getProcessInfo` is the door.
|
|
140
|
+
*/
|
|
141
|
+
const pids = new WeakMap();
|
|
142
|
+
export function pidOf(b) {
|
|
143
|
+
let pid = pids.get(b);
|
|
144
|
+
if (!pid) {
|
|
145
|
+
// Inside `then`, so a handle that cannot open a CDP session (a test double, a
|
|
146
|
+
// non-Chromium browser) rejects into the catch rather than throwing past it.
|
|
147
|
+
pid = Promise.resolve()
|
|
148
|
+
.then(() => b.newBrowserCDPSession())
|
|
149
|
+
.then((s) => s.send('SystemInfo.getProcessInfo'))
|
|
150
|
+
.then((r) => r.processInfo.find((p) => p.type === 'browser')?.id)
|
|
151
|
+
.catch(() => undefined);
|
|
152
|
+
pids.set(b, pid);
|
|
153
|
+
}
|
|
154
|
+
return pid;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* CLOSE A THROWAWAY CHROME WITHOUT WAITING OUT ITS TEARDOWN.
|
|
158
|
+
*
|
|
159
|
+
* `browser.close()` waits for Chrome to EXIT, with no deadline of its own. On a
|
|
160
|
+
* busy machine Chrome's graceful shutdown stalls until its own watchdog fires —
|
|
161
|
+
* MEASURED in the full browser suite: "Teardown watchdog expired; recording dump
|
|
162
|
+
* and terminating" exactly 10.1s after the close, then a crash dump, exit code 2,
|
|
163
|
+
* 10-24s per close. Every import paid it after its result was already in hand,
|
|
164
|
+
* and a 10s test hook could never outlast it. Unloaded, the same close is 0.25s.
|
|
165
|
+
*
|
|
166
|
+
* Every Chrome here runs on a temporary profile Playwright deletes afterwards, so
|
|
167
|
+
* a graceful exit saves nothing. A healthy close is still waited for; one that
|
|
168
|
+
* outlives `graceMs` is SIGKILLed as a process GROUP (Playwright spawns Chrome
|
|
169
|
+
* detached, so its pid leads the group and the helpers go with it), and
|
|
170
|
+
* Playwright's own exit handler then removes the profile.
|
|
171
|
+
*/
|
|
172
|
+
export async function release(b, graceMs = 3_000) {
|
|
173
|
+
// Bounded too: a wedged Chrome may not answer the question either.
|
|
174
|
+
const pid = await Promise.race([pidOf(b), sleep(graceMs, undefined, { ref: false })]);
|
|
175
|
+
const closing = b.close().catch(() => { });
|
|
176
|
+
const stalled = await Promise.race([closing.then(() => false), sleep(graceMs, true, { ref: false })]);
|
|
177
|
+
// No pid, no kill: Chrome's own watchdog still ends it, just not on our clock.
|
|
178
|
+
if (!stalled || !pid)
|
|
179
|
+
return;
|
|
180
|
+
for (const target of [-pid, pid]) {
|
|
181
|
+
try {
|
|
182
|
+
process.kill(target, 'SIGKILL');
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// Not a group leader (or Windows, which has no groups): the pid alone.
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
await closing;
|
|
91
190
|
}
|
|
92
191
|
/**
|
|
93
192
|
* A kept browser is a child process, and a child process outlives a parent that
|
|
@@ -128,15 +227,26 @@ export async function closeBrowser() {
|
|
|
128
227
|
* and a second failing width may go unmentioned.
|
|
129
228
|
*/
|
|
130
229
|
export async function shoot(url, opts = {}) {
|
|
230
|
+
try {
|
|
231
|
+
return await shootWith(await browser(), url, opts);
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
if (!(e instanceof ChromeStalled))
|
|
235
|
+
throw e;
|
|
236
|
+
// The pool would hand every later call this same wedged handle: replace it, once.
|
|
237
|
+
await closeBrowser();
|
|
238
|
+
return shootWith(await browser(), url, opts);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async function shootWith(b, url, opts) {
|
|
131
242
|
const widths = opts.widths ?? DEFAULT_WIDTHS;
|
|
132
243
|
const format = opts.format ?? DEFAULT_FORMAT;
|
|
133
|
-
const b = await browser();
|
|
134
244
|
// Each page closes in ITS OWN finally. A list of pages closed after
|
|
135
245
|
// Promise.all would miss a page whose `newPage` resolved after the first
|
|
136
246
|
// rejection — and now that the browser lives for the whole process, a leaked
|
|
137
247
|
// tab is leaked forever rather than until the next call.
|
|
138
248
|
return Promise.all(widths.map(async (width) => {
|
|
139
|
-
const page = await b.newPage({ viewport: { width, height: 900 } });
|
|
249
|
+
const page = await deadline(b.newPage({ viewport: { width, height: 900 } }), 'open a tab');
|
|
140
250
|
try {
|
|
141
251
|
return await shootOne(page, url, width, format, opts);
|
|
142
252
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sbuilder-mcp",
|
|
3
|
-
"version": "0.100.
|
|
3
|
+
"version": "0.100.4",
|
|
4
4
|
"description": "MCP server that designs and operates a Store Builder site — pages, data, theme and publish — through the platform's own API and live-edit protocol.",
|
|
5
5
|
"mcpName": "io.github.vuluu2k/sbuilder-mcp",
|
|
6
6
|
"type": "module",
|