@auto-wiz/playwright 1.1.3 → 1.2.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/dist/runner.js +97 -3
- package/package.json +7 -4
package/dist/runner.js
CHANGED
|
@@ -108,16 +108,111 @@ class PlaywrightFlowRunner {
|
|
|
108
108
|
return clone.outerHTML;
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
|
+
else if (step.prop === "simplified") {
|
|
112
|
+
// Simplified: Canonical transformation, lighter but preserves hierarchy
|
|
113
|
+
text = await locator.evaluate((el) => {
|
|
114
|
+
const clone = el.cloneNode(true);
|
|
115
|
+
const blockListTags = [
|
|
116
|
+
"SCRIPT",
|
|
117
|
+
"STYLE",
|
|
118
|
+
"SVG",
|
|
119
|
+
"NOSCRIPT",
|
|
120
|
+
"IFRAME",
|
|
121
|
+
"OBJECT",
|
|
122
|
+
"EMBED",
|
|
123
|
+
"PARAM",
|
|
124
|
+
"SOURCE",
|
|
125
|
+
"TRACK",
|
|
126
|
+
"AREA",
|
|
127
|
+
"MAP",
|
|
128
|
+
"META",
|
|
129
|
+
"LINK",
|
|
130
|
+
"HEAD",
|
|
131
|
+
];
|
|
132
|
+
const allowedAttributes = [
|
|
133
|
+
"id",
|
|
134
|
+
"name",
|
|
135
|
+
"href",
|
|
136
|
+
"src",
|
|
137
|
+
"alt",
|
|
138
|
+
"value",
|
|
139
|
+
"type",
|
|
140
|
+
"placeholder",
|
|
141
|
+
"title",
|
|
142
|
+
"colspan",
|
|
143
|
+
"rowspan",
|
|
144
|
+
"target",
|
|
145
|
+
];
|
|
146
|
+
const isGenericContainer = (tagName) => ["DIV", "SPAN"].includes(tagName);
|
|
147
|
+
function clean(node) {
|
|
148
|
+
if (blockListTags.includes(node.tagName)) {
|
|
149
|
+
node.remove();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const children = Array.from(node.children);
|
|
153
|
+
for (const child of children) {
|
|
154
|
+
clean(child);
|
|
155
|
+
}
|
|
156
|
+
const attrs = Array.from(node.attributes || []);
|
|
157
|
+
for (const attr of attrs) {
|
|
158
|
+
if (!allowedAttributes.includes(attr.name)) {
|
|
159
|
+
node.removeAttribute(attr.name);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (isGenericContainer(node.tagName)) {
|
|
163
|
+
const hasIdOrName = node.hasAttribute("id") || node.hasAttribute("name");
|
|
164
|
+
if (hasIdOrName) {
|
|
165
|
+
const hasChildNodes = node.childNodes.length > 0;
|
|
166
|
+
if (!hasChildNodes) {
|
|
167
|
+
node.remove();
|
|
168
|
+
}
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const childElements = node.children;
|
|
172
|
+
let hasText = false;
|
|
173
|
+
for (const childNode of Array.from(node.childNodes)) {
|
|
174
|
+
if (childNode.nodeType === 3 &&
|
|
175
|
+
(childNode.textContent || "").trim() !== "") {
|
|
176
|
+
hasText = true;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (node.tagName === "SPAN") {
|
|
181
|
+
const parent = node.parentNode;
|
|
182
|
+
if (parent) {
|
|
183
|
+
while (node.firstChild) {
|
|
184
|
+
parent.insertBefore(node.firstChild, node);
|
|
185
|
+
}
|
|
186
|
+
parent.removeChild(node);
|
|
187
|
+
}
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (childElements.length === 1 && !hasText) {
|
|
191
|
+
const singleChild = childElements[0];
|
|
192
|
+
const parent = node.parentNode;
|
|
193
|
+
if (parent) {
|
|
194
|
+
node.replaceWith(singleChild);
|
|
195
|
+
}
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (childElements.length === 0 && !hasText) {
|
|
199
|
+
node.remove();
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
clean(clone);
|
|
205
|
+
return clone.outerHTML;
|
|
206
|
+
});
|
|
207
|
+
}
|
|
111
208
|
else {
|
|
112
209
|
// Default "structure": clean HTML, keep only id, name, text
|
|
113
210
|
text = await locator.evaluate(function (el) {
|
|
114
211
|
const clone = el.cloneNode(true);
|
|
115
|
-
// 1. Remove SVGs first
|
|
116
212
|
const svgs = clone.querySelectorAll("svg");
|
|
117
213
|
for (const svg of Array.from(svgs)) {
|
|
118
214
|
svg.remove();
|
|
119
215
|
}
|
|
120
|
-
// 2. Clean attributes of all descendants
|
|
121
216
|
const descendants = clone.querySelectorAll("*");
|
|
122
217
|
for (const child of Array.from(descendants)) {
|
|
123
218
|
const attrs = Array.from(child.attributes);
|
|
@@ -127,7 +222,6 @@ class PlaywrightFlowRunner {
|
|
|
127
222
|
}
|
|
128
223
|
}
|
|
129
224
|
}
|
|
130
|
-
// 3. Clean attributes of the root element itself
|
|
131
225
|
const rootAttrs = Array.from(clone.attributes);
|
|
132
226
|
for (const attr of rootAttrs) {
|
|
133
227
|
if (attr.name !== "id" && attr.name !== "name") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auto-wiz/playwright",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "JaeSang",
|
|
6
6
|
"repository": {
|
|
@@ -22,13 +22,16 @@
|
|
|
22
22
|
"require": "./dist/index.js"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@auto-wiz/core": "^1.1.4"
|
|
27
|
+
},
|
|
25
28
|
"dependencies": {
|
|
26
|
-
"playwright": "^1.40.0"
|
|
27
|
-
"@auto-wiz/core": "1.1.3"
|
|
29
|
+
"playwright": "^1.40.0"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
32
|
"typescript": "^5.0.0",
|
|
31
|
-
"@types/node": "^20.0.0"
|
|
33
|
+
"@types/node": "^20.0.0",
|
|
34
|
+
"@auto-wiz/core": "1.1.4"
|
|
32
35
|
},
|
|
33
36
|
"scripts": {
|
|
34
37
|
"build": "tsc"
|