cypress-annotate 0.4.0 → 1.1.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/AGENTS.md +40 -28
- package/CHANGELOG.md +174 -0
- package/DOCS/images/crop.png +0 -0
- package/DOCS/images/failure-hook.png +0 -0
- package/DOCS/internals.md +151 -0
- package/README.md +104 -352
- package/dist/annotate-image.d.ts +19 -2
- package/dist/annotate-image.d.ts.map +1 -1
- package/dist/annotate-image.js +55 -12
- package/dist/cypress/commands.d.ts +6 -1
- package/dist/cypress/commands.d.ts.map +1 -1
- package/dist/cypress/commands.js +20 -6
- package/dist/cypress/config.d.ts +42 -0
- package/dist/cypress/config.d.ts.map +1 -0
- package/dist/cypress/config.js +102 -0
- package/dist/cypress/failure-hook.d.ts.map +1 -1
- package/dist/cypress/failure-hook.js +17 -3
- package/dist/cypress/failure-report.d.ts +6 -0
- package/dist/cypress/failure-report.d.ts.map +1 -1
- package/dist/cypress/failure-report.js +14 -4
- package/dist/cypress/task.d.ts +39 -3
- package/dist/cypress/task.d.ts.map +1 -1
- package/dist/cypress/task.js +61 -5
- package/dist/draw.d.ts +4 -0
- package/dist/draw.d.ts.map +1 -1
- package/dist/draw.js +7 -4
- package/dist/index.d.ts +9 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -57
- package/dist/types.d.ts +13 -69
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -43
- package/skills/cypress-annotate/SKILL.md +62 -9
- package/DOCS/pipeline.md +0 -308
- package/dist/annotate.d.ts +0 -9
- package/dist/annotate.d.ts.map +0 -1
- package/dist/annotate.js +0 -82
- package/dist/browser/collect-elements.js +0 -158
- package/dist/browser/measure-target.js +0 -69
- package/dist/claude-reasoner.d.ts +0 -17
- package/dist/claude-reasoner.d.ts.map +0 -1
- package/dist/claude-reasoner.js +0 -192
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -84
- package/dist/cypress/failure-explainer.d.ts +0 -45
- package/dist/cypress/failure-explainer.d.ts.map +0 -1
- package/dist/cypress/failure-explainer.js +0 -123
- package/dist/finder.d.ts +0 -68
- package/dist/finder.d.ts.map +0 -1
- package/dist/finder.js +0 -64
- package/dist/inventory.d.ts +0 -33
- package/dist/inventory.d.ts.map +0 -1
- package/dist/inventory.js +0 -88
- package/dist/measure.d.ts +0 -11
- package/dist/measure.d.ts.map +0 -1
- package/dist/measure.js +0 -145
- package/dist/pipeline.d.ts +0 -60
- package/dist/pipeline.d.ts.map +0 -1
- package/dist/pipeline.js +0 -115
- package/skills/annotate-bug/SKILL.md +0 -121
- package/src/browser/collect-elements.js +0 -158
- package/src/browser/measure-target.js +0 -69
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
// This file is read as text and evaluated inside the page - it is never
|
|
2
|
-
// imported or bundled. Keeping it out of the TypeScript build is deliberate:
|
|
3
|
-
// esbuild's keepNames transform injects a `__name` helper into any function it
|
|
4
|
-
// compiles, and that helper does not exist in the browser, so a serialized
|
|
5
|
-
// TypeScript function throws `__name is not defined` on evaluation.
|
|
6
|
-
//
|
|
7
|
-
// The whole file is therefore a single arrow-function expression.
|
|
8
|
-
//
|
|
9
|
-
// Tags every candidate element with a ref attribute and returns a description
|
|
10
|
-
// of it. Tagging rather than deriving a selector afterwards is deliberate: a
|
|
11
|
-
// selector we injected always resolves, whereas a path built from classes can
|
|
12
|
-
// be invalidated by anything that re-renders between measuring and annotating.
|
|
13
|
-
|
|
14
|
-
(function (options) {
|
|
15
|
-
var prefix = options.prefix;
|
|
16
|
-
var refAttr = options.refAttr;
|
|
17
|
-
var minSize = options.minSize;
|
|
18
|
-
var viewportOnly = options.viewportOnly;
|
|
19
|
-
|
|
20
|
-
var INTERACTIVE = ['a', 'button', 'input', 'select', 'textarea', 'label', 'summary', 'option'];
|
|
21
|
-
var STRUCTURAL = ['header', 'nav', 'main', 'footer', 'aside', 'form', 'table', 'img', 'svg', 'video', 'dialog'];
|
|
22
|
-
var HEADING = /^h[1-6]$/;
|
|
23
|
-
var testAttrs = ['data-testid', 'data-test-id', 'data-test', 'data-cy', 'data-qa'];
|
|
24
|
-
|
|
25
|
-
function readableSelector(el) {
|
|
26
|
-
// Prefer whatever a developer would actually paste into devtools.
|
|
27
|
-
var id = el.getAttribute('id');
|
|
28
|
-
if (id && /^[A-Za-z][\w-]*$/.test(id) && el.ownerDocument.querySelectorAll('#' + id).length === 1) {
|
|
29
|
-
return '#' + id;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
for (var i = 0; i < testAttrs.length; i++) {
|
|
33
|
-
var value = el.getAttribute(testAttrs[i]);
|
|
34
|
-
if (value) {
|
|
35
|
-
var candidate = '[' + testAttrs[i] + '="' + value + '"]';
|
|
36
|
-
if (el.ownerDocument.querySelectorAll(candidate).length === 1) return candidate;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
var parts = [];
|
|
41
|
-
var node = el;
|
|
42
|
-
for (var depth = 0; node && depth < 4; depth++) {
|
|
43
|
-
var tag = node.tagName.toLowerCase();
|
|
44
|
-
if (tag === 'body' || tag === 'html') break;
|
|
45
|
-
|
|
46
|
-
var nodeId = node.getAttribute('id');
|
|
47
|
-
if (nodeId && /^[A-Za-z][\w-]*$/.test(nodeId)) {
|
|
48
|
-
parts.unshift('#' + nodeId);
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
var parent = node.parentElement;
|
|
53
|
-
var part = tag;
|
|
54
|
-
if (parent) {
|
|
55
|
-
var siblings = [];
|
|
56
|
-
for (var c = 0; c < parent.children.length; c++) {
|
|
57
|
-
if (parent.children[c].tagName === node.tagName) siblings.push(parent.children[c]);
|
|
58
|
-
}
|
|
59
|
-
if (siblings.length > 1) part += ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')';
|
|
60
|
-
}
|
|
61
|
-
parts.unshift(part);
|
|
62
|
-
|
|
63
|
-
var joined = parts.join(' > ');
|
|
64
|
-
try {
|
|
65
|
-
if (el.ownerDocument.querySelectorAll(joined).length === 1) return joined;
|
|
66
|
-
} catch (e) {
|
|
67
|
-
// An unusual tag name can produce an invalid selector; keep walking.
|
|
68
|
-
}
|
|
69
|
-
node = parent;
|
|
70
|
-
}
|
|
71
|
-
return parts.join(' > ') || el.tagName.toLowerCase();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function accessibleName(el) {
|
|
75
|
-
var aria = el.getAttribute('aria-label');
|
|
76
|
-
if (aria) return aria.trim();
|
|
77
|
-
var alt = el.getAttribute('alt');
|
|
78
|
-
if (alt) return alt.trim();
|
|
79
|
-
var placeholder = el.getAttribute('placeholder');
|
|
80
|
-
if (placeholder) return 'placeholder: ' + placeholder.trim();
|
|
81
|
-
if (el.tagName === 'INPUT' && typeof el.value === 'string' && el.value) {
|
|
82
|
-
return 'value: ' + el.value.trim();
|
|
83
|
-
}
|
|
84
|
-
return (el.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 80);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// An element a developer deliberately named is worth listing even when it is
|
|
88
|
-
// just a wrapper - a misaligned or overflowing container is exactly the kind
|
|
89
|
-
// of target whose children, not itself, carry the text.
|
|
90
|
-
function hasStableName(el) {
|
|
91
|
-
if (el.hasAttribute('id')) return true;
|
|
92
|
-
for (var i = 0; i < testAttrs.length; i++) {
|
|
93
|
-
if (el.hasAttribute(testAttrs[i])) return true;
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Text-bearing leaf: has its own text but no child element that also has text.
|
|
99
|
-
function isTextLeaf(el) {
|
|
100
|
-
if (!(el.textContent || '').trim()) return false;
|
|
101
|
-
for (var i = 0; i < el.children.length; i++) {
|
|
102
|
-
if ((el.children[i].textContent || '').trim()) return false;
|
|
103
|
-
}
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Clear handles left by an earlier pass. Counters restart at 1 each time, so
|
|
108
|
-
// without this a stale e5 from a previous scroll position still matches
|
|
109
|
-
// [data-annot-ref="e5"] and the annotation can land on the wrong element.
|
|
110
|
-
var stale = document.querySelectorAll('[' + refAttr + ']');
|
|
111
|
-
for (var s = 0; s < stale.length; s++) stale[s].removeAttribute(refAttr);
|
|
112
|
-
|
|
113
|
-
var results = [];
|
|
114
|
-
var counter = 0;
|
|
115
|
-
var all = document.querySelectorAll('*');
|
|
116
|
-
|
|
117
|
-
for (var i = 0; i < all.length; i++) {
|
|
118
|
-
var el = all[i];
|
|
119
|
-
var tag = el.tagName.toLowerCase();
|
|
120
|
-
if (tag === 'script' || tag === 'style' || tag === 'meta' || tag === 'link') continue;
|
|
121
|
-
|
|
122
|
-
var style = getComputedStyle(el);
|
|
123
|
-
if (style.visibility === 'hidden' || style.display === 'none') continue;
|
|
124
|
-
if (parseFloat(style.opacity) < 0.05) continue;
|
|
125
|
-
|
|
126
|
-
var rect = el.getBoundingClientRect();
|
|
127
|
-
if (rect.width < minSize || rect.height < minSize) continue;
|
|
128
|
-
|
|
129
|
-
var intersects =
|
|
130
|
-
rect.bottom > 0 && rect.right > 0 &&
|
|
131
|
-
rect.top < window.innerHeight && rect.left < window.innerWidth;
|
|
132
|
-
if (viewportOnly && !intersects) continue;
|
|
133
|
-
|
|
134
|
-
var interesting =
|
|
135
|
-
INTERACTIVE.indexOf(tag) !== -1 ||
|
|
136
|
-
STRUCTURAL.indexOf(tag) !== -1 ||
|
|
137
|
-
HEADING.test(tag) ||
|
|
138
|
-
el.hasAttribute('role') ||
|
|
139
|
-
hasStableName(el) ||
|
|
140
|
-
isTextLeaf(el);
|
|
141
|
-
if (!interesting) continue;
|
|
142
|
-
|
|
143
|
-
var ref = prefix + ++counter;
|
|
144
|
-
el.setAttribute(refAttr, ref);
|
|
145
|
-
|
|
146
|
-
results.push({
|
|
147
|
-
ref: ref,
|
|
148
|
-
reportSelector: readableSelector(el),
|
|
149
|
-
tag: tag,
|
|
150
|
-
role: el.getAttribute('role'),
|
|
151
|
-
name: accessibleName(el),
|
|
152
|
-
rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
153
|
-
inViewport: intersects,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return results;
|
|
158
|
-
})
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// Paste this into whichever browser MCP is live, as the evaluate function:
|
|
2
|
-
//
|
|
3
|
-
// Playwright MCP browser_evaluate({ function: "<this>", filename: "measure.json" })
|
|
4
|
-
// Chrome DevTools evaluate_script({ pageId, function: "<this>", filePath: "measure.json" })
|
|
5
|
-
//
|
|
6
|
-
// Edit the SELECTORS line, and nothing else. The result is the exact JSON that
|
|
7
|
-
// `annotate-shot --measurement` expects.
|
|
8
|
-
//
|
|
9
|
-
// It deliberately does not scroll, click, or change anything: every rectangle it
|
|
10
|
-
// returns is only valid for the scroll position the page is in right now, so
|
|
11
|
-
// the screenshot must be taken immediately after this runs, with no navigation
|
|
12
|
-
// in between.
|
|
13
|
-
|
|
14
|
-
() => {
|
|
15
|
-
const SELECTORS = ['#place-order'];
|
|
16
|
-
|
|
17
|
-
const doc = document.documentElement;
|
|
18
|
-
const body = document.body;
|
|
19
|
-
|
|
20
|
-
const metrics = {
|
|
21
|
-
devicePixelRatio: window.devicePixelRatio,
|
|
22
|
-
scrollX: window.scrollX,
|
|
23
|
-
scrollY: window.scrollY,
|
|
24
|
-
// innerWidth/Height rather than documentElement.clientWidth/Height: on a
|
|
25
|
-
// page with no doctype (quirks mode) the root element reports the content
|
|
26
|
-
// size, not the viewport.
|
|
27
|
-
viewportWidth: window.innerWidth,
|
|
28
|
-
viewportHeight: window.innerHeight,
|
|
29
|
-
documentWidth: Math.max(doc.scrollWidth, body ? body.scrollWidth : 0),
|
|
30
|
-
documentHeight: Math.max(doc.scrollHeight, body ? body.scrollHeight : 0),
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const targets = SELECTORS.map((selector) => {
|
|
34
|
-
let matches;
|
|
35
|
-
try {
|
|
36
|
-
matches = document.querySelectorAll(selector);
|
|
37
|
-
} catch (e) {
|
|
38
|
-
return { selector, found: false, error: 'invalid selector: ' + e.message };
|
|
39
|
-
}
|
|
40
|
-
if (matches.length === 0) return { selector, found: false, error: 'no element matched' };
|
|
41
|
-
|
|
42
|
-
const el = matches[0];
|
|
43
|
-
const r = el.getBoundingClientRect();
|
|
44
|
-
|
|
45
|
-
// An element inside a fixed subtree does not move with document scroll, so
|
|
46
|
-
// it has no meaningful document-space position.
|
|
47
|
-
let isFixed = false;
|
|
48
|
-
for (let node = el; node; node = node.parentElement) {
|
|
49
|
-
if (getComputedStyle(node).position === 'fixed') {
|
|
50
|
-
isFixed = true;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
selector,
|
|
57
|
-
found: true,
|
|
58
|
-
matchCount: matches.length,
|
|
59
|
-
tag: el.tagName.toLowerCase(),
|
|
60
|
-
text: (el.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 80),
|
|
61
|
-
isFixed,
|
|
62
|
-
rect: { x: r.x, y: r.y, width: r.width, height: r.height },
|
|
63
|
-
inViewport:
|
|
64
|
-
r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth,
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return { metrics, targets };
|
|
69
|
-
}
|