@operstack/audit 0.3.0 → 0.3.1

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/package.json +1 -1
  2. package/src/collect.mjs +13 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@operstack/audit",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "SEO, AEO and GEO audit generator: collect public signals from a site into audit.json, let an analyst or an agent fill the narrative, render the OperStack report as HTML and PDF.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/collect.mjs CHANGED
@@ -77,7 +77,19 @@ function analysePage(url, html) {
77
77
  const formEls = root.querySelectorAll('form');
78
78
  const realForms = formEls.filter((f) => !/search/i.test(`${f.getAttribute('class') || ''} ${f.getAttribute('id') || ''} ${f.getAttribute('role') || ''} ${f.getAttribute('action') || ''}`));
79
79
  const firstForm = realForms[0] || null;
80
- const formFields = firstForm ? firstForm.querySelectorAll('input, textarea, select').filter((i) => !/^(hidden|submit|button|image)$/i.test(i.getAttribute('type') || '')).length : 0;
80
+ // A honeypot is invisible to a person, so counting it as a field the visitor must fill is wrong.
81
+ const visibleToVisitor = (el) => {
82
+ if (el.getAttribute('tabindex') === '-1') return false;
83
+ if (/honeypot|\bhp\b/i.test(`${el.getAttribute('class') || ''} ${el.getAttribute('name') || ''}`)) return false;
84
+ for (let n = el.parentNode; n; n = n.parentNode) {
85
+ if (typeof n.getAttribute !== 'function') break;
86
+ if (n.getAttribute('aria-hidden') === 'true') return false;
87
+ if (/honeypot|\bhp\b/i.test(n.getAttribute('class') || '')) return false;
88
+ if (/display:\s*none|visibility:\s*hidden/i.test(n.getAttribute('style') || '')) return false;
89
+ }
90
+ return true;
91
+ };
92
+ const formFields = firstForm ? firstForm.querySelectorAll('input, textarea, select').filter((i) => !/^(hidden|submit|button|image)$/i.test(i.getAttribute('type') || '')).filter(visibleToVisitor).length : 0;
81
93
  const formAt = firstForm ? bodyInner.indexOf(firstForm.outerHTML.slice(0, 120)) : -1;
82
94
  const formDepth = firstForm && formAt >= 0 && bodyInner.length ? Math.round((formAt / bodyInner.length) * 100) : null;
83
95
  const firstScreen = bodyInner.slice(0, Math.max(1200, Math.round(bodyInner.length * 0.15)));