@9l/playwright 0.2.5 → 0.3.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.md +1 -1
- package/dist/goal.js +34 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ completing does not verify that behavior.
|
|
|
10
10
|
Published on [npm](https://www.npmjs.com/package/@9l/playwright):
|
|
11
11
|
|
|
12
12
|
```sh
|
|
13
|
-
npm install --save-dev @9l/playwright@0.
|
|
13
|
+
npm install --save-dev @9l/playwright@0.3.0 @playwright/test@1.64.0
|
|
14
14
|
npm exec playwright install chromium
|
|
15
15
|
```
|
|
16
16
|
|
package/dist/goal.js
CHANGED
|
@@ -56,7 +56,25 @@ async function metadata(handle) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
const policyText = [element.getAttribute('aria-label'), labelled, Array.from(input.labels || []).map(label => label.textContent || '').join(' '), element.textContent, ['submit', 'button', 'reset'].includes(type) ? input.value : ''].filter(Boolean).join(' ');
|
|
59
|
-
|
|
59
|
+
let context = '';
|
|
60
|
+
for (let scope = element.parentElement; scope; scope = scope.parentElement) {
|
|
61
|
+
const scopeTag = scope.tagName.toLowerCase();
|
|
62
|
+
const scopeRole = (scope.getAttribute('role') || '').trim().toLowerCase().split(/\s+/)[0];
|
|
63
|
+
const named = (scope.getAttribute('aria-labelledby') || '').split(/\s+/).map(id => document.getElementById(id)?.textContent || '').join(' ').trim();
|
|
64
|
+
const ariaName = (scope.getAttribute('aria-label') || named).trim();
|
|
65
|
+
const landmarkRoles = ['banner', 'complementary', 'contentinfo', 'form', 'main', 'navigation', 'region', 'search'];
|
|
66
|
+
const implicitLandmark = !scopeRole && (scopeTag === 'main' || scopeTag === 'nav' || scopeTag === 'aside'
|
|
67
|
+
|| scopeTag === 'section' && !!ariaName
|
|
68
|
+
|| ['header', 'footer'].includes(scopeTag) && !scope.parentElement?.closest('article,aside,main,nav,section'));
|
|
69
|
+
const scopeLandmark = landmarkRoles.includes(scopeRole) && (!['form', 'region'].includes(scopeRole) || !!ariaName);
|
|
70
|
+
if (['form', 'fieldset', 'dialog'].includes(scopeTag) || ['dialog', 'alertdialog', 'form'].includes(scopeRole) || scopeLandmark || implicitLandmark) {
|
|
71
|
+
const legend = scopeTag === 'fieldset' ? scope.querySelector(':scope > legend')?.textContent || '' : '';
|
|
72
|
+
context = ariaName || legend || scope.querySelector('h1,h2,h3,h4,h5,h6')?.textContent || scope.getAttribute('name') || '';
|
|
73
|
+
if (context)
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return { role, label, policyText, actions, context, fingerprint: JSON.stringify([tag, type, role, label, href, policyText, context]) };
|
|
60
78
|
});
|
|
61
79
|
}
|
|
62
80
|
/** Redacts the test's parameter values, including whitespace-collapsed forms, then bounds the label. */
|
|
@@ -82,6 +100,7 @@ async function observe(page, redact) {
|
|
|
82
100
|
handles.push(handle);
|
|
83
101
|
}
|
|
84
102
|
const targets = new Map();
|
|
103
|
+
const contexts = new Map();
|
|
85
104
|
// Bound traversal as well as the transmitted set.
|
|
86
105
|
for (const handle of handles.slice(0, 100)) {
|
|
87
106
|
if (targets.size >= 25 || !await handle.isVisible() || !await handle.isEnabled())
|
|
@@ -90,7 +109,20 @@ async function observe(page, redact) {
|
|
|
90
109
|
if (!data)
|
|
91
110
|
continue;
|
|
92
111
|
const id = `target-${targets.size + 1}`;
|
|
93
|
-
targets.set(id, { handle, fingerprint: data.fingerprint, control: { id, role: data.role, label: redact(data.label), actions: data.actions, blocked: risky.test(data.policyText) } });
|
|
112
|
+
targets.set(id, { handle, fingerprint: data.fingerprint, control: { id, role: data.role, label: redact(data.label), actions: data.actions, blocked: risky.test(`${data.policyText} ${data.context}`) } });
|
|
113
|
+
contexts.set(id, data.context);
|
|
114
|
+
}
|
|
115
|
+
// Controls that share role and label get their context and a 1-based
|
|
116
|
+
// ordinal among those duplicates; unique controls stay unchanged.
|
|
117
|
+
const groups = new Map();
|
|
118
|
+
for (const target of targets.values()) {
|
|
119
|
+
const key = JSON.stringify([target.control.role, target.control.label]);
|
|
120
|
+
groups.set(key, [...(groups.get(key) || []), target]);
|
|
121
|
+
}
|
|
122
|
+
for (const group of groups.values()) {
|
|
123
|
+
if (group.length < 2)
|
|
124
|
+
continue;
|
|
125
|
+
group.forEach((target, index) => { target.control.context = redact(contexts.get(target.control.id) || ''); target.control.ordinal = index + 1; });
|
|
94
126
|
}
|
|
95
127
|
const state = await observeState(page, redact);
|
|
96
128
|
return { targets, state, dispose: async () => { await Promise.allSettled(handles.map(handle => handle.dispose())); } };
|
package/package.json
CHANGED