mosaic-headless 1.40.3 → 1.41.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/README.ja.md +2 -2
- package/README.ko.md +2 -2
- package/README.md +2 -2
- package/README.zh-TW.md +2 -2
- package/SKILL.md +1 -1
- package/assets/templates/platforms/claude-ai.json +1 -1
- package/assets/templates/platforms/claude-code.json +1 -1
- package/assets/templates/platforms/codex-cli.json +1 -1
- package/assets/templates/platforms/copilot.json +1 -1
- package/assets/templates/platforms/gemini-cli.json +1 -1
- package/package.json +1 -1
- package/references/facts.md +12 -0
- package/references/tools.md +1 -1
- package/tools/test_mosaic.py +15 -0
- package/tools/verify_browser.py +245 -1
package/README.ja.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<img src="https://img.shields.io/badge/node_properties-120-success?style=flat-square" alt="120 個の node プロパティ">
|
|
19
19
|
<img src="https://img.shields.io/badge/style_properties-101-success?style=flat-square" alt="101 個のスタイルプロパティ">
|
|
20
20
|
<img src="https://img.shields.io/badge/responsive_checks-733-blueviolet?style=flat-square" alt="733 件のレスポンシブ検査">
|
|
21
|
-
<img src="https://img.shields.io/badge/self--tests-
|
|
21
|
+
<img src="https://img.shields.io/badge/self--tests-56-blueviolet?style=flat-square" alt="56 項目のセルフテスト">
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
24
|
<p align="center">
|
|
@@ -183,7 +183,7 @@ node type、node プロパティ、スタイルプロパティ、スタイル状
|
|
|
183
183
|
| `data/theme-zip-verification.csv` | 22 | Mosaic 自身のテーマ ZIP を往復させて比較 |
|
|
184
184
|
| `data/conversion-batch.csv` | 19 | あるサイトのすべての Elementor ページを変換・構築・検査 |
|
|
185
185
|
|
|
186
|
-
- セルフテスト:`python tools/test_mosaic.py`、オフラインの
|
|
186
|
+
- セルフテスト:`python tools/test_mosaic.py`、オフラインの 56 項目(検索、中国語の用語、構築結果の形と拒否ルール、公開されている構築インターフェース、このリポジトリの数値とプライバシー)。
|
|
187
187
|
- evals:Mosaic 1.0.10〜1.0.12 の挙動に関する 16 問。skill ありで 16/16、なしで 0/16。結果:[evals/RESULTS.md](evals/RESULTS.md)。
|
|
188
188
|
- `SKILL.md`、これらの README、バッジの数値は、`tools/check_numbers.py` がデータと照合しています。詳細:[verification-record.md](references/verification-record.md)。
|
|
189
189
|
|
package/README.ko.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<img src="https://img.shields.io/badge/node_properties-120-success?style=flat-square" alt="120개 node 속성">
|
|
19
19
|
<img src="https://img.shields.io/badge/style_properties-101-success?style=flat-square" alt="101개 스타일 속성">
|
|
20
20
|
<img src="https://img.shields.io/badge/responsive_checks-733-blueviolet?style=flat-square" alt="733개 반응형 검사">
|
|
21
|
-
<img src="https://img.shields.io/badge/self--tests-
|
|
21
|
+
<img src="https://img.shields.io/badge/self--tests-56-blueviolet?style=flat-square" alt="56개 자체 테스트">
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
24
|
<p align="center">
|
|
@@ -183,7 +183,7 @@ node type, node 속성, 스타일 속성, 스타일 상태는 플러그인 소
|
|
|
183
183
|
| `data/theme-zip-verification.csv` | 22 | Mosaic 자체 테마 ZIP을 왕복시켜 비교 |
|
|
184
184
|
| `data/conversion-batch.csv` | 19 | 한 사이트의 모든 Elementor 페이지를 변환, 구축, 검사 |
|
|
185
185
|
|
|
186
|
-
- 자체 테스트: `python tools/test_mosaic.py`, 오프라인 테스트
|
|
186
|
+
- 자체 테스트: `python tools/test_mosaic.py`, 오프라인 테스트 56개(조회, 중국어 용어, 구축 결과의 형태와 거부 규칙, 공개된 구축 인터페이스, 이 저장소의 숫자와 개인정보).
|
|
187
187
|
- evals: Mosaic 1.0.10~1.0.12 동작에 관한 16문항. skill 사용 시 16/16, 미사용 시 0/16. 결과: [evals/RESULTS.md](evals/RESULTS.md).
|
|
188
188
|
- `SKILL.md`, 이 README들, 배지의 숫자는 `tools/check_numbers.py`가 데이터와 대조합니다. 자세한 내용: [verification-record.md](references/verification-record.md).
|
|
189
189
|
|
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<img src="https://img.shields.io/badge/node_properties-120-success?style=flat-square" alt="120 node properties">
|
|
19
19
|
<img src="https://img.shields.io/badge/style_properties-101-success?style=flat-square" alt="101 style properties">
|
|
20
20
|
<img src="https://img.shields.io/badge/responsive_checks-733-blueviolet?style=flat-square" alt="733 responsive checks">
|
|
21
|
-
<img src="https://img.shields.io/badge/self--tests-
|
|
21
|
+
<img src="https://img.shields.io/badge/self--tests-56-blueviolet?style=flat-square" alt="56 self-tests">
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
24
|
<p align="center">
|
|
@@ -183,7 +183,7 @@ Node types, node properties, style properties and style states are extracted fro
|
|
|
183
183
|
| `data/theme-zip-verification.csv` | 22 | Mosaic's own theme ZIP round-tripped and compared |
|
|
184
184
|
| `data/conversion-batch.csv` | 19 | every Elementor page of a site converted, built and checked |
|
|
185
185
|
|
|
186
|
-
- Self-test: `python tools/test_mosaic.py`,
|
|
186
|
+
- Self-test: `python tools/test_mosaic.py`, 56 offline tests (lookups, Chinese terms, the build output's shape and refusals, the public build interface, this repository's numbers and privacy).
|
|
187
187
|
- Evals: 16 questions about Mosaic 1.0.10 to 1.0.12 behaviour; with the skill 16/16, without it 0/16. Results: [evals/RESULTS.md](evals/RESULTS.md).
|
|
188
188
|
- Every number in `SKILL.md`, these READMEs and their badges is checked against the data by `tools/check_numbers.py`. Detail: [verification-record.md](references/verification-record.md).
|
|
189
189
|
|
package/README.zh-TW.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<img src="https://img.shields.io/badge/node_properties-120-success?style=flat-square" alt="120 個 node 屬性">
|
|
19
19
|
<img src="https://img.shields.io/badge/style_properties-101-success?style=flat-square" alt="101 個樣式屬性">
|
|
20
20
|
<img src="https://img.shields.io/badge/responsive_checks-733-blueviolet?style=flat-square" alt="733 條 RWD 檢查">
|
|
21
|
-
<img src="https://img.shields.io/badge/self--tests-
|
|
21
|
+
<img src="https://img.shields.io/badge/self--tests-56-blueviolet?style=flat-square" alt="56 項自我測試">
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
24
|
<p align="center">
|
|
@@ -183,7 +183,7 @@ node type、node 屬性、樣式屬性、樣式狀態從外掛原始碼抽出(
|
|
|
183
183
|
| `data/theme-zip-verification.csv` | 22 | Mosaic 自己的佈景 ZIP 匯出再匯入並比對 |
|
|
184
184
|
| `data/conversion-batch.csv` | 19 | 一個網站的每個 Elementor 頁面都轉換、建置並檢查 |
|
|
185
185
|
|
|
186
|
-
- 自我測試:`python tools/test_mosaic.py`,
|
|
186
|
+
- 自我測試:`python tools/test_mosaic.py`,56 項離線測試(查詢、中文用語、建頁產出的結構與拒收規則、對外的建頁介面、本 repo 的數字與隱私)。
|
|
187
187
|
- evals:16 題 Mosaic 1.0.10 到 1.0.12 的行為題;有 skill 16/16,沒有 skill 0/16。結果見 [evals/RESULTS.md](evals/RESULTS.md)。
|
|
188
188
|
- `SKILL.md`、這幾份 README 和徽章上的數字,都由 `tools/check_numbers.py` 對照資料核對。細節見 [verification-record.md](references/verification-record.md)。
|
|
189
189
|
|
package/SKILL.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mosaic-headless",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.41.0",
|
|
4
4
|
"description": "AI-agent skill: build Mosaic Pro (Nextend) WordPress sites by writing the underlying data model directly - 23 custom tables, no visual editor, no DOM. Every node type, style property and node property swept against a live install and asserted on the delivered HTML and compiled CSS. Installs into Claude Code, Cursor, Codex CLI, Gemini CLI, Copilot, Continue, Windsurf and Claude.ai.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wordpress",
|
package/references/facts.md
CHANGED
|
@@ -147,6 +147,18 @@ Platform and rendered-tag facts, each measured. Moved out of SKILL.md on 2026-11
|
|
|
147
147
|
whose spec set neither; between a masthead and the block below it that is a
|
|
148
148
|
160px hole. Set `paddingTop`/`paddingBottom` explicitly when a section's rhythm
|
|
149
149
|
is meant to come from its contents.
|
|
150
|
+
- **`button` arrives with `padding: 12px 24px`, so a round button is an ellipse until
|
|
151
|
+
all four paddings are 0.** `.m-button{…width:fit-content;padding:12px 24px;…}` in the
|
|
152
|
+
1.0.14 stylesheet (the `:where(button.m-button)` reset to `padding:0` has no
|
|
153
|
+
specificity and loses). Measured on the demo site (1.0.14, Chromium, 1440px,
|
|
154
|
+
`getBoundingClientRect`, at rest and hovered): a button with no style is 48 x 24;
|
|
155
|
+
`width`/`height` 44px with `borderRadius` 999px - or 50% - renders **48 x 44**,
|
|
156
|
+
because 24 + 24 > 44; the same button with `paddingTop`, `paddingBottom`,
|
|
157
|
+
`paddingLeft` and `paddingRight` all `0px` renders 44 x 44. Reported first from a
|
|
158
|
+
client site (four 44px circles at 48 x 44, 44 x 44 after the fix). The fill that
|
|
159
|
+
shows the shape is often a `hover` background, so a screenshot at rest looks fine:
|
|
160
|
+
`verify_browser.py` reports it as `ROUND_NOT_ROUND`, measured hovered too
|
|
161
|
+
(`--round URL` runs that check alone on any public page).
|
|
150
162
|
- **A `code` node's content is a template, and `@media(` is a function call.**
|
|
151
163
|
Mosaic parses `code` content for `@VAR(...)`; a CSS at-rule glued to its
|
|
152
164
|
parenthesis - the form every minifier emits - is parsed as a call with
|
package/references/tools.md
CHANGED
|
@@ -11,7 +11,7 @@ Every tool in `tools/`, and where the REST session comes from. Moved out of SKIL
|
|
|
11
11
|
| `build_page.py` | commit one page spec through the verified write path |
|
|
12
12
|
| `build_site.py` | a whole site: one master with the shell, one document per page. It makes a NEW master and new templates on EVERY run and re-binds every page it builds, so a one-line change means a full rebuild, and building only some pages leaves the site split across masters (a header edit then reaches some pages and not others). For changes to a built site use `sync_nodes.py` |
|
|
13
13
|
| `verify_rwd.py` | does every `_t`/`_m` declaration reach the served stylesheet? |
|
|
14
|
-
| `verify_browser.py` | does the **browser** compute what the stylesheet promised - and does the result pass a design audit? |
|
|
14
|
+
| `verify_browser.py` | does the **browser** compute what the stylesheet promised - and does the result pass a design audit? The audit includes `ROUND_NOT_ROUND`: every element whose corners are all >= 999px or >= 50% is measured with `getBoundingClientRect` at rest and hovered, and an unequal width and height is an error (a pill longer than 1.5 : 1, or one showing more than 2 characters of text, is not). `--round URL ...` runs that check alone on any public page: no spec, no session, images and fonts not fetched, stops at the first 403 |
|
|
15
15
|
| `verify_intro.py` | does the page-load animation play, and - the part that matters - does it END and hand the page back? |
|
|
16
16
|
| `verify_menus.py` | build and drive every site-menu option: does hover hold, do the keyboard and a touch tablet work, does the phone drawer trap focus, close on Esc and stay above a sticky header? |
|
|
17
17
|
| `verify_loop.py` | a decoration that runs forever: does it loop (paused-timeline scrub), does it bury text or controls anywhere a reader can rest, does it open by pointer and by keyboard, is it still under reduced motion? |
|
package/tools/test_mosaic.py
CHANGED
|
@@ -407,6 +407,21 @@ class SkillDoc(unittest.TestCase):
|
|
|
407
407
|
self.assertTrue(hits, name)
|
|
408
408
|
|
|
409
409
|
|
|
410
|
+
class RoundCheck(unittest.TestCase):
|
|
411
|
+
"""verify_browser's ROUND_NOT_ROUND decision, without a browser."""
|
|
412
|
+
|
|
413
|
+
def test_round_and_oval(self):
|
|
414
|
+
import verify_browser as vb
|
|
415
|
+
self.assertTrue(vb._is_round(["999px"] * 4))
|
|
416
|
+
self.assertTrue(vb._is_round(["50%"] * 4))
|
|
417
|
+
self.assertFalse(vb._is_round(["999px", "999px", "0px", "999px"]))
|
|
418
|
+
self.assertFalse(vb._is_round(["8px"] * 4))
|
|
419
|
+
self.assertTrue(vb._oval(48, 44)) # the default-padding button
|
|
420
|
+
self.assertFalse(vb._oval(44, 44)) # all four paddings 0
|
|
421
|
+
self.assertFalse(vb._oval(140, 44)) # a pill
|
|
422
|
+
self.assertFalse(vb._oval(44.3, 44)) # sub-pixel rounding
|
|
423
|
+
|
|
424
|
+
|
|
410
425
|
class SyncNodesPlan(unittest.TestCase):
|
|
411
426
|
"""sync_nodes.py's matching, offline: a live document is simulated as the same spec
|
|
412
427
|
flattened again (fresh node ids, the way a commit stores it)."""
|
package/tools/verify_browser.py
CHANGED
|
@@ -557,6 +557,213 @@ PROBE = r"""
|
|
|
557
557
|
"""
|
|
558
558
|
|
|
559
559
|
|
|
560
|
+
# ── ROUND: a circle that is not one ──────────────────────────────────────────
|
|
561
|
+
#
|
|
562
|
+
# A button set to 44 x 44 with `borderRadius: 999px` is meant to be a circle. Mosaic's
|
|
563
|
+
# `.m-button` rule arrives with `padding: 12px 24px`, and 24 + 24 is more than 44, so
|
|
564
|
+
# the box is 48 x 44 - an ellipse - unless every side of the padding is written as 0
|
|
565
|
+
# (references/facts.md). The fill that shows the shape is often a hover colour, so a
|
|
566
|
+
# screenshot at rest sees nothing wrong; the reading has to be taken while hovered too.
|
|
567
|
+
#
|
|
568
|
+
# An element counts as "meant to be round" when every corner's computed radius is
|
|
569
|
+
# >= 999px or >= 50%. Width and height are read with getBoundingClientRect, at rest
|
|
570
|
+
# and again with the pointer on it. A pill - a wide button with a 999px radius - is
|
|
571
|
+
# round by the same test and is not a defect, so only a box whose long side is at
|
|
572
|
+
# most ROUND_PILL_RATIO times its short side is reported: 48 x 44 is 1.09, a
|
|
573
|
+
# "Contact us" pill is 3 or more. A circle that only gets its radius under `:hover`
|
|
574
|
+
# is found from the stylesheet's :hover rules (same-origin sheets only).
|
|
575
|
+
# A short pill exists too - a "Home" nav link at 55 x 40 on a client site - so an
|
|
576
|
+
# element showing more than ROUND_MAX_TEXT characters of text is a labelled pill and
|
|
577
|
+
# is skipped; a circle holds an icon, a number or one character.
|
|
578
|
+
ROUND_PILL_RATIO = 1.5
|
|
579
|
+
ROUND_MAX_TEXT = 2
|
|
580
|
+
|
|
581
|
+
ROUND_JS = r"""
|
|
582
|
+
() => {
|
|
583
|
+
const qual = v => {
|
|
584
|
+
v = (v || '').trim().split(/\s+/)[0];
|
|
585
|
+
if (v.endsWith('%')) return parseFloat(v) >= 50;
|
|
586
|
+
if (v.endsWith('px')) return parseFloat(v) >= 999;
|
|
587
|
+
return false;
|
|
588
|
+
};
|
|
589
|
+
const corners = cs => [cs.borderTopLeftRadius, cs.borderTopRightRadius,
|
|
590
|
+
cs.borderBottomRightRadius, cs.borderBottomLeftRadius];
|
|
591
|
+
const round = cs => corners(cs).every(qual);
|
|
592
|
+
const seen = new Set();
|
|
593
|
+
for (const el of document.body.querySelectorAll('*')) {
|
|
594
|
+
if (round(getComputedStyle(el))) seen.add(el);
|
|
595
|
+
}
|
|
596
|
+
// a radius that only exists under :hover
|
|
597
|
+
const walk = rules => {
|
|
598
|
+
for (const r of rules) {
|
|
599
|
+
if (r.cssRules && !r.selectorText) {
|
|
600
|
+
if (!r.media || matchMedia(r.media.mediaText).matches) walk(r.cssRules);
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (!r.selectorText || !r.selectorText.includes(':hover') || !r.style) continue;
|
|
604
|
+
const s = r.style;
|
|
605
|
+
if (![s.borderTopLeftRadius, s.borderTopRightRadius,
|
|
606
|
+
s.borderBottomRightRadius, s.borderBottomLeftRadius].every(qual)) continue;
|
|
607
|
+
try {
|
|
608
|
+
document.querySelectorAll(r.selectorText.replace(/:hover/g, ''))
|
|
609
|
+
.forEach(el => seen.add(el));
|
|
610
|
+
} catch (e) {}
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
for (const sh of document.styleSheets) {
|
|
614
|
+
try { walk(sh.cssRules); } catch (e) {} // cross-origin sheet
|
|
615
|
+
}
|
|
616
|
+
const out = [];
|
|
617
|
+
let i = 0;
|
|
618
|
+
for (const el of seen) {
|
|
619
|
+
const cs = getComputedStyle(el);
|
|
620
|
+
if (cs.display === 'none' || cs.visibility === 'hidden') continue;
|
|
621
|
+
const r = el.getBoundingClientRect();
|
|
622
|
+
if (r.width < 4 || r.height < 4) continue;
|
|
623
|
+
el.setAttribute('data-round-probe', String(i));
|
|
624
|
+
const cls = (el.getAttribute('class') || '').trim().split(/\s+/).filter(Boolean);
|
|
625
|
+
const label = (el.getAttribute('aria-label') || el.getAttribute('title') ||
|
|
626
|
+
(el.innerText || '').trim()).replace(/\s+/g, ' ').slice(0, 30);
|
|
627
|
+
out.push({i: i, node: el.id || (el.tagName.toLowerCase() +
|
|
628
|
+
(cls.length ? '.' + cls.slice(0, 2).join('.') : '')),
|
|
629
|
+
label: label, href: el.getAttribute('href') || '',
|
|
630
|
+
text: (el.innerText || '').replace(/\s+/g, ''),
|
|
631
|
+
w: r.width, h: r.height, round: round(cs),
|
|
632
|
+
radius: cs.borderTopLeftRadius, padding: cs.padding});
|
|
633
|
+
i++;
|
|
634
|
+
}
|
|
635
|
+
return out;
|
|
636
|
+
}
|
|
637
|
+
"""
|
|
638
|
+
|
|
639
|
+
ROUND_READ_JS = r"""
|
|
640
|
+
el => {
|
|
641
|
+
const cs = getComputedStyle(el);
|
|
642
|
+
const r = el.getBoundingClientRect();
|
|
643
|
+
return {w: r.width, h: r.height, radius: cs.borderTopLeftRadius,
|
|
644
|
+
corners: [cs.borderTopLeftRadius, cs.borderTopRightRadius,
|
|
645
|
+
cs.borderBottomRightRadius, cs.borderBottomLeftRadius],
|
|
646
|
+
padding: cs.padding};
|
|
647
|
+
}
|
|
648
|
+
"""
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
def _is_round(corners):
|
|
652
|
+
for v in corners:
|
|
653
|
+
v = (v or "").split()[0] if (v or "").strip() else ""
|
|
654
|
+
try:
|
|
655
|
+
if v.endswith("%"):
|
|
656
|
+
if float(v[:-1]) < 50:
|
|
657
|
+
return False
|
|
658
|
+
elif v.endswith("px"):
|
|
659
|
+
if float(v[:-2]) < 999:
|
|
660
|
+
return False
|
|
661
|
+
else:
|
|
662
|
+
return False
|
|
663
|
+
except ValueError:
|
|
664
|
+
return False
|
|
665
|
+
return True
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
def _oval(w, h):
|
|
669
|
+
"""Unequal by half a pixel or more, and not long enough to be a pill."""
|
|
670
|
+
lo, hi = min(w, h), max(w, h)
|
|
671
|
+
return lo > 0 and hi - lo >= 0.5 and hi / lo <= ROUND_PILL_RATIO
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
def round_check(page, limit=80):
|
|
675
|
+
"""ROUND_NOT_ROUND findings for the page as it stands: every element whose
|
|
676
|
+
corners are all >= 999px or >= 50%, measured at rest and hovered."""
|
|
677
|
+
found = []
|
|
678
|
+
for c in page.evaluate(ROUND_JS)[:limit]:
|
|
679
|
+
if len(c["text"]) > ROUND_MAX_TEXT:
|
|
680
|
+
continue # a labelled pill, not a circle
|
|
681
|
+
rest = c if c["round"] else None
|
|
682
|
+
hover = None
|
|
683
|
+
loc = page.locator('[data-round-probe="%d"]' % c["i"])
|
|
684
|
+
try:
|
|
685
|
+
loc.hover(timeout=1500, force=True)
|
|
686
|
+
page.wait_for_timeout(350) # most hover transitions are <= 300ms
|
|
687
|
+
got = loc.evaluate(ROUND_READ_JS)
|
|
688
|
+
if _is_round(got["corners"]):
|
|
689
|
+
hover = got
|
|
690
|
+
except Exception:
|
|
691
|
+
pass # off-screen, covered, or gone
|
|
692
|
+
try:
|
|
693
|
+
page.mouse.move(0, 0)
|
|
694
|
+
except Exception:
|
|
695
|
+
pass
|
|
696
|
+
bad = []
|
|
697
|
+
if rest and _oval(rest["w"], rest["h"]):
|
|
698
|
+
bad.append("%gx%g at rest" % (round(rest["w"], 1), round(rest["h"], 1)))
|
|
699
|
+
if hover and _oval(hover["w"], hover["h"]):
|
|
700
|
+
bad.append("%gx%g hovered" % (round(hover["w"], 1), round(hover["h"], 1)))
|
|
701
|
+
if not bad:
|
|
702
|
+
continue
|
|
703
|
+
seen = hover or rest
|
|
704
|
+
found.append({
|
|
705
|
+
"check": "ROUND_NOT_ROUND", "level": "error", "node": c["node"],
|
|
706
|
+
"detail": "radius %s but %s (padding %s)"
|
|
707
|
+
% (seen["radius"], ", ".join(bad), seen["padding"]),
|
|
708
|
+
"sample": (c["label"] or c["href"])[:30],
|
|
709
|
+
})
|
|
710
|
+
return found
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
def round_scan(urls, viewports, block_media=True, gap_ms=1500):
|
|
714
|
+
"""The ROUND check alone, on public URLs, with no spec and no REST session.
|
|
715
|
+
|
|
716
|
+
Made for reading a front end that is not yours: no cache-buster (the cached copy
|
|
717
|
+
is what a visitor gets and costs the server nothing), images, video and fonts are
|
|
718
|
+
not fetched, one load per URL per viewport with a pause between loads, and the
|
|
719
|
+
run STOPS at the first 401/403/429/503 - the reason is returned, nothing is
|
|
720
|
+
retried."""
|
|
721
|
+
import time
|
|
722
|
+
try:
|
|
723
|
+
from playwright.sync_api import sync_playwright
|
|
724
|
+
except ImportError:
|
|
725
|
+
sys.exit("verify_browser.py needs Playwright:\n"
|
|
726
|
+
" pip install playwright && playwright install chromium")
|
|
727
|
+
findings, stopped, loads = [], None, 0
|
|
728
|
+
|
|
729
|
+
def no_media(route):
|
|
730
|
+
if route.request.resource_type in ("image", "media", "font"):
|
|
731
|
+
route.abort()
|
|
732
|
+
else:
|
|
733
|
+
route.continue_()
|
|
734
|
+
|
|
735
|
+
with sync_playwright() as pw:
|
|
736
|
+
browser = pw.chromium.launch()
|
|
737
|
+
for url in urls:
|
|
738
|
+
for bp, w, h in viewports:
|
|
739
|
+
page = browser.new_page(viewport={"width": w, "height": h},
|
|
740
|
+
device_scale_factor=1)
|
|
741
|
+
if block_media:
|
|
742
|
+
page.route("**/*", no_media)
|
|
743
|
+
try:
|
|
744
|
+
resp = page.goto(url, wait_until="load", timeout=45000)
|
|
745
|
+
loads += 1
|
|
746
|
+
status = resp.status if resp else 0
|
|
747
|
+
if status in (401, 403, 429, 503):
|
|
748
|
+
stopped = "%s answered HTTP %d (%s)" % (url, status, bp)
|
|
749
|
+
else:
|
|
750
|
+
page.wait_for_timeout(1200)
|
|
751
|
+
for f in round_check(page):
|
|
752
|
+
findings.append(dict(f, url=url, breakpoint=bp))
|
|
753
|
+
except Exception as e: # a timeout is reported, not retried
|
|
754
|
+
findings.append({"check": "LOAD", "level": "warn", "url": url,
|
|
755
|
+
"breakpoint": bp, "node": "", "sample": "",
|
|
756
|
+
"detail": str(e).splitlines()[0][:120]})
|
|
757
|
+
page.close()
|
|
758
|
+
if stopped:
|
|
759
|
+
break
|
|
760
|
+
time.sleep(gap_ms / 1000.0)
|
|
761
|
+
if stopped:
|
|
762
|
+
break
|
|
763
|
+
browser.close()
|
|
764
|
+
return findings, stopped, loads
|
|
765
|
+
|
|
766
|
+
|
|
560
767
|
def run(url, ids, shots_dir):
|
|
561
768
|
try:
|
|
562
769
|
from playwright.sync_api import sync_playwright
|
|
@@ -585,6 +792,8 @@ def run(url, ids, shots_dir):
|
|
|
585
792
|
page.screenshot(path=os.path.join(shots_dir, "browser-%s.png"
|
|
586
793
|
% bp.strip("_") or "desktop"),
|
|
587
794
|
full_page=False)
|
|
795
|
+
# after the screenshot, because this one hovers things
|
|
796
|
+
results[bp]["audit"].extend(round_check(page))
|
|
588
797
|
page.close()
|
|
589
798
|
browser.close()
|
|
590
799
|
return results
|
|
@@ -608,7 +817,13 @@ def main():
|
|
|
608
817
|
ap = argparse.ArgumentParser()
|
|
609
818
|
ap.add_argument("--config",
|
|
610
819
|
help="JSON with base/cookie/nonce; omit it and the MOSAIC_SITE_URL / MOSAIC_REST_COOKIE / MOSAIC_REST_NONCE environment variables supply them instead")
|
|
611
|
-
ap.add_argument("--site", required
|
|
820
|
+
ap.add_argument("--site", help="the site spec (required unless --round)")
|
|
821
|
+
ap.add_argument("--round", nargs="+", metavar="URL",
|
|
822
|
+
help="run ONLY the round-element check on these public URLs: "
|
|
823
|
+
"no spec, no REST session, images/fonts not fetched, "
|
|
824
|
+
"stops at the first 403")
|
|
825
|
+
ap.add_argument("--viewports", default="_,_m",
|
|
826
|
+
help="with --round: which of _,_t,_m to load (default _,_m)")
|
|
612
827
|
ap.add_argument("--csv", help="a DIRECTORY: the computed-value table is "
|
|
613
828
|
"written one file per page, <dir>/<slug>.csv")
|
|
614
829
|
ap.add_argument("--audit", help="the design-audit findings")
|
|
@@ -620,6 +835,10 @@ def main():
|
|
|
620
835
|
ap.add_argument("--page", help="only this slug")
|
|
621
836
|
a = ap.parse_args()
|
|
622
837
|
|
|
838
|
+
if a.round:
|
|
839
|
+
sys.exit(main_round(a))
|
|
840
|
+
if not a.site:
|
|
841
|
+
ap.error("--site is required (or use --round URL ...)")
|
|
623
842
|
cfg = mosaic_config.load(a.config)
|
|
624
843
|
spec = json.load(open(a.site, encoding="utf-8"))
|
|
625
844
|
|
|
@@ -797,5 +1016,30 @@ def main():
|
|
|
797
1016
|
sys.exit(1 if hard else 0)
|
|
798
1017
|
|
|
799
1018
|
|
|
1019
|
+
def main_round(a):
|
|
1020
|
+
want = [v.strip() for v in a.viewports.split(",") if v.strip()]
|
|
1021
|
+
vps = [v for v in VIEWPORTS if v[0] in want]
|
|
1022
|
+
findings, stopped, loads = round_scan(a.round, vps)
|
|
1023
|
+
errors = [f for f in findings if f["level"] == "error"]
|
|
1024
|
+
print("round check: %d URL(s), %d page loads, %d finding(s)"
|
|
1025
|
+
% (len(a.round), loads, len(errors)))
|
|
1026
|
+
for f in findings:
|
|
1027
|
+
print(" %-5s %-4s %-40s %-28s %s %s"
|
|
1028
|
+
% (f["level"], f["breakpoint"], f["url"][-40:], f["node"][:28],
|
|
1029
|
+
f["detail"], f.get("sample", "")))
|
|
1030
|
+
if a.audit:
|
|
1031
|
+
with open(a.audit, "w", newline="", encoding="utf-8") as fh:
|
|
1032
|
+
w = csv.writer(fh)
|
|
1033
|
+
w.writerow(["url", "breakpoint", "check", "level", "node", "detail",
|
|
1034
|
+
"sample"])
|
|
1035
|
+
for f in findings:
|
|
1036
|
+
w.writerow([f["url"], f["breakpoint"], f["check"], f["level"],
|
|
1037
|
+
f["node"], f["detail"], f.get("sample", "")])
|
|
1038
|
+
if stopped:
|
|
1039
|
+
print("STOPPED - " + stopped)
|
|
1040
|
+
return 2
|
|
1041
|
+
return 1 if errors else 0
|
|
1042
|
+
|
|
1043
|
+
|
|
800
1044
|
if __name__ == "__main__":
|
|
801
1045
|
main()
|