sbuilder-mcp 0.100.3 → 0.100.5
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 +17 -0
- package/CHANGELOG.vi.md +17 -0
- package/dist/catalog/deadkeys.generated.js +2 -2
- package/dist/catalog/elements.generated.js +32 -0
- package/dist/catalog/shapes.generated.js +1 -1
- package/dist/catalog/source.generated.js +2 -2
- package/dist/domains/site/review.js +18 -8
- package/dist/tools/live.js +18 -2
- package/dist/vision/capture.js +21 -12
- package/dist/vision/imagediff.js +3 -1
- package/dist/vision/measure.js +14 -8
- package/dist/vision/shoot.js +125 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,23 @@ 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.5] - 2026-10-29
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
- `sb_bind` returns `collapsed` with the replaced sources and a one-time note when it replaces a field's chain of several bindings with one.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- `sb_look` measurements report `off_canvas` for a hidden absolute box, such as a closed dropdown panel, that still widens the page, and skip only hidden boxes inside a fixed layer, such as a closed drawer.
|
|
16
|
+
- `sb_look` no longer treats `aria-hidden` boxes as hidden, and hidden boxes still count for width but not for overlap or small text.
|
|
17
|
+
- `sb_look` turns off CSS transitions before measuring, so an overlay opened just before measuring is measured at its final position.
|
|
18
|
+
- `sb_review` reports `duplicate_binding_field` only when a binding is shadowed by a source that is always present, because a binding before a present-only source such as `product.summary`, `rating` or `record.*` is a fallback.
|
|
19
|
+
|
|
20
|
+
## [0.100.4] - 2026-10-29
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
- `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.
|
|
24
|
+
- 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.
|
|
25
|
+
|
|
9
26
|
## [0.100.3] - 2026-10-29
|
|
10
27
|
|
|
11
28
|
### Changed
|
package/CHANGELOG.vi.md
CHANGED
|
@@ -6,6 +6,23 @@ 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.5] - 2026-10-29
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
- `sb_bind` trả về `collapsed` cùng các nguồn bị thay và một ghi chú một lần khi thay chuỗi nhiều binding của một field bằng một binding duy nhất.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- Phép đo của `sb_look` báo `off_canvas` cho hộp ẩn dạng absolute, như panel dropdown đang đóng, mà vẫn làm trang rộng ra, và chỉ bỏ qua hộp ẩn nằm trong lớp fixed, như drawer đang đóng.
|
|
16
|
+
- `sb_look` không còn coi hộp `aria-hidden` là ẩn, và hộp ẩn vẫn được tính vào bề rộng nhưng không tính vào overlap hay chữ nhỏ.
|
|
17
|
+
- `sb_look` tắt CSS transition trước khi đo, nên overlay vừa mở được đo ở vị trí cuối.
|
|
18
|
+
- `sb_review` chỉ báo `duplicate_binding_field` khi binding bị che bởi một nguồn luôn có, vì binding đứng trước nguồn present-only như `product.summary`, `rating` hay `record.*` là dự phòng.
|
|
19
|
+
|
|
20
|
+
## [0.100.4] - 2026-10-29
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
- `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.
|
|
24
|
+
- 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ả.
|
|
25
|
+
|
|
9
26
|
## [0.100.3] - 2026-10-29
|
|
10
27
|
|
|
11
28
|
### Changed
|
|
@@ -36400,6 +36400,38 @@ export const BINDING_SOURCES = [
|
|
|
36400
36400
|
"site.timezone",
|
|
36401
36401
|
"site.youtube"
|
|
36402
36402
|
];
|
|
36403
|
+
/** Sources a context holds only when the entity has one (scripts/gen-catalog.ts readPresentOnlySources). */
|
|
36404
|
+
export const PRESENT_ONLY_SOURCES = [
|
|
36405
|
+
"course.ratingAverage",
|
|
36406
|
+
"course.ratingCount",
|
|
36407
|
+
"product.attributes",
|
|
36408
|
+
"product.brandLogo",
|
|
36409
|
+
"product.brandUrl",
|
|
36410
|
+
"product.bundleItems",
|
|
36411
|
+
"product.id",
|
|
36412
|
+
"product.model",
|
|
36413
|
+
"product.ratingAverage",
|
|
36414
|
+
"product.ratingCount",
|
|
36415
|
+
"product.summary",
|
|
36416
|
+
"product.tags",
|
|
36417
|
+
"product.variations",
|
|
36418
|
+
"site.addressLine",
|
|
36419
|
+
"site.country",
|
|
36420
|
+
"site.description",
|
|
36421
|
+
"site.facebook",
|
|
36422
|
+
"site.instagram",
|
|
36423
|
+
"site.localeSwitch",
|
|
36424
|
+
"site.moneySwitch",
|
|
36425
|
+
"site.postalCode",
|
|
36426
|
+
"site.privacyPolicy",
|
|
36427
|
+
"site.province",
|
|
36428
|
+
"site.returnPolicy",
|
|
36429
|
+
"site.shippingPolicy",
|
|
36430
|
+
"site.supportEmail",
|
|
36431
|
+
"site.supportPhone",
|
|
36432
|
+
"site.tiktok",
|
|
36433
|
+
"site.youtube"
|
|
36434
|
+
];
|
|
36403
36435
|
export const BOUND_SPECIALS = {
|
|
36404
36436
|
"bundle-items": [
|
|
36405
36437
|
"boundBundleItems"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// GENERATED by scripts/gen-catalog.ts — do not edit by hand.
|
|
2
2
|
// The platform commit every other generated file here describes.
|
|
3
3
|
export const PLATFORM_SOURCE = {
|
|
4
|
-
"commit": "
|
|
5
|
-
"committedAt": "2026-10-
|
|
4
|
+
"commit": "ae1e972c66244b299ac4b5460be740a680f63844",
|
|
5
|
+
"committedAt": "2026-10-29T19:22:08+07:00",
|
|
6
6
|
"dirty": false
|
|
7
7
|
};
|
|
@@ -5,7 +5,7 @@ import { bandOf, isGlobal } from './traps.js';
|
|
|
5
5
|
import { exampleCopy } from './examplecopy.js';
|
|
6
6
|
import { SEED_COPY_VI, langOf } from './seedcopy.js';
|
|
7
7
|
import { HOVER_STATE, hoverHome } from './hover.js';
|
|
8
|
-
import { ELEMENTS, BINDING_SOURCES, BOUND_SPECIALS, FIRST_CHILD_ONLY, SATELLITE_RULES, ELEMENT_SEEDS } from '../../catalog/elements.generated.js';
|
|
8
|
+
import { ELEMENTS, BINDING_SOURCES, PRESENT_ONLY_SOURCES, BOUND_SPECIALS, FIRST_CHILD_ONLY, SATELLITE_RULES, ELEMENT_SEEDS } from '../../catalog/elements.generated.js';
|
|
9
9
|
import { fill } from './findings.js';
|
|
10
10
|
import { hrefParamProblems, isRecordSource, isSameSitePath, parseRecordRefAxis, readRecordAggregates, recordAggKeyOf, recordAggregateParams, RECORD_FIELD_ID, RECORD_HTML_SOURCE, RECORD_SOURCE, RECORD_TILES, recordScope, } from './record.js';
|
|
11
11
|
import { formFieldFindings, isFormDocument } from './formdoc.js';
|
|
@@ -1541,26 +1541,36 @@ opts = {}) {
|
|
|
1541
1541
|
}
|
|
1542
1542
|
}
|
|
1543
1543
|
// TWO BINDINGS ON ONE FIELD (TTG gap #62). ApplyBindings
|
|
1544
|
-
// (render/scope/scope.go) walks them IN ORDER
|
|
1545
|
-
//
|
|
1546
|
-
//
|
|
1544
|
+
// (render/scope/scope.go) walks them IN ORDER, SKIPS a source the context
|
|
1545
|
+
// does not hold, and each resolved one overwrites the special — so the last
|
|
1546
|
+
// source THE CONTEXT RESOLVES wins. An earlier binding is dead only under a
|
|
1547
|
+
// later source that is ALWAYS there: same context (namespace) and not
|
|
1548
|
+
// present-only. Under `product.tags`, `product.summary`, a rating or a
|
|
1549
|
+
// `record.*` field it is the fallback for an entity without one, and a
|
|
1550
|
+
// source from another context may be outside this node's scope altogether.
|
|
1551
|
+
// The purchase binding is not a field binding.
|
|
1547
1552
|
const byField = new Map();
|
|
1548
1553
|
for (const b of bindings) {
|
|
1549
1554
|
if (!b.field || !b.source || b.id === PRODUCT_ACTION_BINDING_ID)
|
|
1550
1555
|
continue;
|
|
1551
1556
|
byField.set(b.field, [...(byField.get(b.field) ?? []), b.source]);
|
|
1552
1557
|
}
|
|
1558
|
+
const ns = (s) => s.split('.')[0];
|
|
1559
|
+
const always = (s) => ns(s) !== 'record' && !PRESENT_ONLY_SOURCES.includes(s);
|
|
1553
1560
|
for (const [field, sources] of byField) {
|
|
1554
|
-
|
|
1561
|
+
const shadow = (i) => sources.slice(i + 1).filter((t) => ns(t) === ns(sources[i]) && always(t)).pop();
|
|
1562
|
+
const deadAt = sources.map((_, i) => i).filter((i) => shadow(i));
|
|
1563
|
+
if (!deadAt.length)
|
|
1555
1564
|
continue;
|
|
1556
|
-
const
|
|
1565
|
+
const dead = deadAt.map((i) => sources[i]);
|
|
1557
1566
|
out.push({
|
|
1558
1567
|
code: 'duplicate_binding_field',
|
|
1559
1568
|
nodeId: id,
|
|
1560
1569
|
type,
|
|
1561
1570
|
key: field,
|
|
1562
|
-
problem: `${sources.length} bindings write ${field} (${sources.join(', ')}); the renderer applies them in ` +
|
|
1563
|
-
`
|
|
1571
|
+
problem: `${sources.length} bindings write ${field} (${sources.join(', ')}); the renderer applies them in order ` +
|
|
1572
|
+
`and the last source the context resolves wins, so ${dead.join(', ')} never renders — ` +
|
|
1573
|
+
`${shadow(deadAt[0])} always resolves after it.`,
|
|
1564
1574
|
fix: fill('duplicate_binding_field', { id, key: field }),
|
|
1565
1575
|
});
|
|
1566
1576
|
}
|
package/dist/tools/live.js
CHANGED
|
@@ -882,11 +882,27 @@ export function registerLiveTools(server, ctx, session) {
|
|
|
882
882
|
}
|
|
883
883
|
}
|
|
884
884
|
const forced = guard.forced.length ? { forced: guard.forced } : {};
|
|
885
|
+
// A FALLBACK CHAIN COLLAPSED. ApplyBindings skips a source the context
|
|
886
|
+
// lacks, so earlier bindings under a present-only one (product.summary,
|
|
887
|
+
// tags, rating, record.*) render when it is absent. Replacing them all is
|
|
888
|
+
// what a rebind asks for — and is said, since it can lose a fallback.
|
|
889
|
+
const prior = action === undefined
|
|
890
|
+
? (d.node(id).bindings ?? [])
|
|
891
|
+
.filter((b) => b?.field === field && b.id !== PRODUCT_ACTION_BINDING_ID)
|
|
892
|
+
.map((b) => b.source ?? '')
|
|
893
|
+
: [];
|
|
894
|
+
const collapsed = prior.length > 1
|
|
895
|
+
? {
|
|
896
|
+
collapsed: prior,
|
|
897
|
+
collapsed_note: (dry_run !== false ? ctx.notices.peek : ctx.notices.once).call(ctx.notices, 'bind:collapsed', `${field} held a chain; the renderer shows the last source the context resolves, so an earlier one was ` +
|
|
898
|
+
'a fallback for an entity without the later one. Now one binding — rebind each if the chain was wanted.'),
|
|
899
|
+
}
|
|
900
|
+
: {};
|
|
885
901
|
if (dry_run !== false) {
|
|
886
902
|
const refuse = session.wouldRefuse(patches);
|
|
887
|
-
return text({ dry_run: true, patches, ...(refuse ? { would_refuse: refuse } : {}), ...forced });
|
|
903
|
+
return text({ dry_run: true, patches, ...(refuse ? { would_refuse: refuse } : {}), ...collapsed, ...forced });
|
|
888
904
|
}
|
|
889
905
|
await session.applyAndSave(patches);
|
|
890
|
-
return text({ bound: id, source, field, ...(action ? { action } : {}), rev: d.rev, ...forced });
|
|
906
|
+
return text({ bound: id, source, field, ...(action ? { action } : {}), ...collapsed, rev: d.rev, ...forced });
|
|
891
907
|
});
|
|
892
908
|
}
|
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/measure.js
CHANGED
|
@@ -33,16 +33,21 @@ export function measureShot(shot, skip = new Set(), doc) {
|
|
|
33
33
|
// that is two dozen false positives long is a list nobody reads.
|
|
34
34
|
if (skip.has(b.id))
|
|
35
35
|
continue;
|
|
36
|
-
// A
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
|
|
36
|
+
// A CLOSED DRAWER is `visibility:hidden` AND fixed, translated off-screen by
|
|
37
|
+
// its own static CSS: nothing a visitor sees or scrolls to (TTG gap #60).
|
|
38
|
+
// Hidden is PAINT only, though — a hidden ABSOLUTE panel (a closed dropdown,
|
|
39
|
+
// a reveal-on-hover child) still lays out and still widens the page:
|
|
40
|
+
// measured, a 320px `.wb-dropdown-panel` at x=200 made a 390 phone scroll
|
|
41
|
+
// to 520 (review of v0.100.4). So only hidden-in-a-fixed-layer is skipped.
|
|
42
|
+
if (b.hidden && (b.inFixed || b.position === 'fixed'))
|
|
40
43
|
continue;
|
|
41
44
|
// A FLOATING BOX PAST THE VIEWPORT (TTG gap #60). A fixed drawer 400px wide
|
|
42
45
|
// on a 390px phone overhangs by 10px with no scrollbar to show it — headless
|
|
43
46
|
// has none, and a 24px padding hides most of it in the picture. Out of the
|
|
44
|
-
// flow nothing shrinks it, so the fix is a cap, said with the widths.
|
|
45
|
-
|
|
47
|
+
// flow nothing shrinks it, so the fix is a cap, said with the widths. A
|
|
48
|
+
// HIDDEN one is not seen at all; what it costs is the scroll (off_canvas).
|
|
49
|
+
if (!b.hidden &&
|
|
50
|
+
(b.position === 'fixed' || b.position === 'sticky' || b.position === 'absolute') &&
|
|
46
51
|
(b.x < -1 || b.x + b.w > shot.width + 1)) {
|
|
47
52
|
out.push({
|
|
48
53
|
code: 'wider_than_viewport',
|
|
@@ -60,13 +65,14 @@ export function measureShot(shot, skip = new Set(), doc) {
|
|
|
60
65
|
code: 'off_canvas',
|
|
61
66
|
nodeId: b.id,
|
|
62
67
|
width: shot.width,
|
|
63
|
-
problem:
|
|
68
|
+
problem: (b.hidden ? 'Hidden, yet still laid out — it widens the page: ' : '') +
|
|
69
|
+
`Extends past the ${shot.width}px viewport (${b.x} → ${b.x + b.w}).`,
|
|
64
70
|
fix: fill('off_canvas', { id: b.id }),
|
|
65
71
|
});
|
|
66
72
|
}
|
|
67
73
|
// TEXT TOO SMALL. Only where text actually renders: a container inherits a
|
|
68
74
|
// font size it never shows, and reporting that would be noise.
|
|
69
|
-
if (b.hasText && b.fontPx && b.fontPx < MIN_BODY_PX) {
|
|
75
|
+
if (!b.hidden && b.hasText && b.fontPx && b.fontPx < MIN_BODY_PX) {
|
|
70
76
|
out.push({
|
|
71
77
|
code: 'text_too_small',
|
|
72
78
|
nodeId: b.id,
|
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
|
}
|
|
@@ -279,7 +389,10 @@ async function settleLazyImages(page) {
|
|
|
279
389
|
*/
|
|
280
390
|
async function settleAnimations(page) {
|
|
281
391
|
await page
|
|
282
|
-
|
|
392
|
+
// TRANSITION TOO: an overlay opened just before measuring slides in under
|
|
393
|
+
// its own transition (cart drawer `transform .25s`), and a shot mid-slide
|
|
394
|
+
// measures a box that is not where it ends. `none` jumps to the end value.
|
|
395
|
+
.addStyleTag({ content: '*,*::before,*::after{animation:none !important;transition:none !important}' })
|
|
283
396
|
.catch(() => { });
|
|
284
397
|
}
|
|
285
398
|
async function shootOne(page, url, width, format, opts) {
|
|
@@ -346,8 +459,11 @@ async function shootOne(page, url, width, format, opts) {
|
|
|
346
459
|
const cs = getComputedStyle(el);
|
|
347
460
|
const own = (el.textContent ?? '').trim();
|
|
348
461
|
let layer;
|
|
349
|
-
|
|
350
|
-
|
|
462
|
+
let inFixed = false;
|
|
463
|
+
for (let e = el; e && !inFixed; e = e.parentElement) {
|
|
464
|
+
const p = getComputedStyle(e).position;
|
|
465
|
+
inFixed = p === 'fixed';
|
|
466
|
+
if (layer !== undefined || !['absolute', 'fixed', 'sticky'].includes(p))
|
|
351
467
|
continue;
|
|
352
468
|
if (!e.id && !anon.has(e))
|
|
353
469
|
anon.set(e, `@${anon.size}`);
|
|
@@ -364,7 +480,8 @@ async function shootOne(page, url, width, format, opts) {
|
|
|
364
480
|
hasText: own.length > 0,
|
|
365
481
|
position: cs.position,
|
|
366
482
|
...(layer ? { layer } : {}),
|
|
367
|
-
...(cs.visibility !== 'visible'
|
|
483
|
+
...(cs.visibility !== 'visible' ? { hidden: true } : {}),
|
|
484
|
+
...(inFixed ? { inFixed: true } : {}),
|
|
368
485
|
};
|
|
369
486
|
});
|
|
370
487
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sbuilder-mcp",
|
|
3
|
-
"version": "0.100.
|
|
3
|
+
"version": "0.100.5",
|
|
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",
|