@auto-wiz/playwright 1.1.1 → 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.
Files changed (2) hide show
  1. package/dist/runner.js +112 -16
  2. package/package.json +7 -4
package/dist/runner.js CHANGED
@@ -108,30 +108,126 @@ class PlaywrightFlowRunner {
108
108
  return clone.outerHTML;
109
109
  });
110
110
  }
111
- else {
112
- // Default "structure": clean HTML, keep only id, name, text
111
+ else if (step.prop === "simplified") {
112
+ // Simplified: Canonical transformation, lighter but preserves hierarchy
113
113
  text = await locator.evaluate((el) => {
114
114
  const clone = el.cloneNode(true);
115
- function cleanElement(element) {
116
- // Remove all attributes except id and name
117
- const attributes = Array.from(element.attributes);
118
- for (const attr of attributes) {
119
- if (!["id", "name"].includes(attr.name)) {
120
- element.removeAttribute(attr.name);
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);
121
160
  }
122
161
  }
123
- // DFS for children
124
- for (const child of Array.from(element.children)) {
125
- // Remove SVGs entirely
126
- if (child.tagName.toLowerCase() === "svg") {
127
- child.remove();
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
+ }
128
179
  }
129
- else {
130
- cleanElement(child);
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
+ }
208
+ else {
209
+ // Default "structure": clean HTML, keep only id, name, text
210
+ text = await locator.evaluate(function (el) {
211
+ const clone = el.cloneNode(true);
212
+ const svgs = clone.querySelectorAll("svg");
213
+ for (const svg of Array.from(svgs)) {
214
+ svg.remove();
215
+ }
216
+ const descendants = clone.querySelectorAll("*");
217
+ for (const child of Array.from(descendants)) {
218
+ const attrs = Array.from(child.attributes);
219
+ for (const attr of attrs) {
220
+ if (attr.name !== "id" && attr.name !== "name") {
221
+ child.removeAttribute(attr.name);
131
222
  }
132
223
  }
133
224
  }
134
- cleanElement(clone);
225
+ const rootAttrs = Array.from(clone.attributes);
226
+ for (const attr of rootAttrs) {
227
+ if (attr.name !== "id" && attr.name !== "name") {
228
+ clone.removeAttribute(attr.name);
229
+ }
230
+ }
135
231
  return clone.outerHTML;
136
232
  });
137
233
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auto-wiz/playwright",
3
- "version": "1.1.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.1"
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"