@reshotdev/screenshot 0.0.1-beta.10 → 0.0.1-beta.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reshotdev/screenshot",
3
- "version": "0.0.1-beta.10",
3
+ "version": "0.0.1-beta.11",
4
4
  "description": "CI/CD screenshot and video capture CLI",
5
5
  "author": "Reshot <hello@reshot.dev>",
6
6
  "license": "MIT",
@@ -165,7 +165,61 @@ async function assertForbiddenTextAbsent(page, forbidText = []) {
165
165
  }
166
166
 
167
167
  const visibleText = normalizeVisibleText(
168
- await page.evaluate(() => document.body?.innerText || ""),
168
+ await page.evaluate(() => {
169
+ const isElementVisibleInViewport = (element) => {
170
+ if (!(element instanceof Element)) {
171
+ return false;
172
+ }
173
+
174
+ const style = window.getComputedStyle(element);
175
+ if (
176
+ style.display === "none" ||
177
+ style.visibility === "hidden" ||
178
+ Number(style.opacity || "1") === 0
179
+ ) {
180
+ return false;
181
+ }
182
+
183
+ const rect = element.getBoundingClientRect();
184
+ if (rect.width <= 0 || rect.height <= 0) {
185
+ return false;
186
+ }
187
+
188
+ return (
189
+ rect.bottom > 0 &&
190
+ rect.right > 0 &&
191
+ rect.top < window.innerHeight &&
192
+ rect.left < window.innerWidth
193
+ );
194
+ };
195
+
196
+ const walker = document.createTreeWalker(
197
+ document.body,
198
+ NodeFilter.SHOW_TEXT,
199
+ {
200
+ acceptNode(node) {
201
+ const text = node.textContent?.replace(/\s+/g, " ").trim();
202
+ if (!text) {
203
+ return NodeFilter.FILTER_REJECT;
204
+ }
205
+
206
+ const parent = node.parentElement;
207
+ if (!parent || !isElementVisibleInViewport(parent)) {
208
+ return NodeFilter.FILTER_REJECT;
209
+ }
210
+
211
+ return NodeFilter.FILTER_ACCEPT;
212
+ },
213
+ },
214
+ );
215
+
216
+ const textParts = [];
217
+ while (walker.nextNode()) {
218
+ textParts.push(walker.currentNode.textContent || "");
219
+ }
220
+
221
+ return textParts.join(" ");
222
+ }),
169
223
  );
170
224
  const matched = forbidText.find((candidate) =>
171
225
  visibleText.includes(normalizeVisibleText(candidate)),