// Febe: targets from the everyday browser (docs/prove-dal-vivo.md, part «A bis»; hypothesis H11). // // Paste it in the Console of the browser's DevTools, with the site open and already logged in, then browse by hand. // For every click it records the shape of the address before and about 1.5 s after, and the attributes of the clicked // command that Febe's target map uses (src/Febe.Core/Config/bersagli..json): role, accessible name computed as // src/Febe.Browser/Targets/TargetResolver.cs computes it, link shape. At the end, febeBersagli() copies the records. // // READ-ONLY with respect to the page: one capturing click listener that never blocks or changes the click, and // attribute reads. It never changes the DOM, never sends anything anywhere, never reads cookies or the browser's // storage. Records stay in this tab's memory; reloading the page drops them (paste it again after a reload). // Address segments that are not fixed words become «»; user names seen in the addresses and @words become «NOME». (() => { 'use strict'; if (typeof globalThis.febeBersagli === 'function') { console.log('Febe: la raccolta dei bersagli è già attiva. febeBersagli() copia ciò che è stato registrato.'); return; } const FIXED = new Set(['stories', 'highlights', 'p', 'reel', 'reels', 'tagged', 'following', 'followers', 'explore']); const MAX_TEXT = 80; const records = []; const names = new Set(); // Same as TargetResolver.cs: collapsed whitespace. const clean = (s) => (s || '').replace(/\s+/g, ' ').trim(); // The shape of a path: fixed words stay, every other segment becomes «». The segments that are not fixed words // are kept aside (in memory only) to mask them in the recorded texts. const shapeOf = (path) => { if (typeof path !== 'string') return null; return path.split('/').map((segment) => { if (segment === '' || FIXED.has(segment.toLowerCase())) return segment; let decoded = segment; try { decoded = decodeURIComponent(segment); } catch { /* keep it as it is */ } if (decoded.length >= 2) names.add(decoded.toLowerCase()); return ''; }).join('/'); }; // Same as TargetResolver.cs roleOf: explicit role first, then the implicit role of the tag. const roleOf = (el) => { const explicit = clean(el.getAttribute('role')).split(' ')[0]; if (explicit) return explicit.toLowerCase(); const tag = el.tagName.toLowerCase(); const type = (el.getAttribute('type') || '').toLowerCase(); switch (tag) { case 'a': case 'area': return el.hasAttribute('href') ? 'link' : ''; case 'button': return 'button'; case 'input': if (['button', 'submit', 'reset', 'image'].includes(type)) return 'button'; if (type === 'checkbox') return 'checkbox'; if (type === 'radio') return 'radio'; if (type === 'search') return 'searchbox'; if (['', 'text', 'email', 'tel', 'url', 'password'].includes(type)) return 'textbox'; return ''; case 'textarea': return 'textbox'; case 'select': return 'combobox'; case 'img': return el.getAttribute('alt') === '' ? 'presentation' : 'img'; case 'h1': case 'h2': case 'h3': case 'h4': case 'h5': case 'h6': return 'heading'; case 'nav': return 'navigation'; case 'main': return 'main'; case 'dialog': return 'dialog'; case 'article': return 'article'; case 'ul': case 'ol': return 'list'; case 'li': return 'listitem'; case 'section': return (el.hasAttribute('aria-label') || el.hasAttribute('aria-labelledby')) ? 'region' : ''; default: return ''; } }; // Same as TargetResolver.cs textOf: a child's aria-label stands for its subtree, aria-hidden children are skipped. const textOf = (node, depth) => { if (depth > 25) return ''; let out = ''; for (const child of node.childNodes) { if (child.nodeType === 3) { out += child.nodeValue + ' '; continue; } if (child.nodeType !== 1) continue; if (child.getAttribute('aria-hidden') === 'true') continue; const label = clean(child.getAttribute('aria-label')); if (label) { out += label + ' '; continue; } const tag = child.tagName.toLowerCase(); if (tag === 'img') { out += (child.getAttribute('alt') || '') + ' '; continue; } if (tag === 'script' || tag === 'style' || tag === 'template') continue; out += textOf(child, depth + 1) + ' '; } return out; }; // Roles named from their content (TargetResolver.cs fromContent): only these get their text recorded. const fromContent = new Set(['button', 'link', 'tab', 'menuitem', 'heading', 'cell', 'gridcell', 'option', 'checkbox', 'radio', 'switch', 'listitem', 'treeitem', 'columnheader', 'rowheader', 'tooltip']); // Same as TargetResolver.cs nameOf: the accessible name the «name» field of the map is matched against. const nameOf = (el, role) => { const ids = clean(el.getAttribute('aria-labelledby')); if (ids) { const joined = clean(ids.split(' ').map((id) => document.getElementById(id)).filter(Boolean).map((e) => e.textContent).join(' ')); if (joined) return joined; } const aria = clean(el.getAttribute('aria-label')); if (aria) return aria; const tag = el.tagName.toLowerCase(); const type = (el.getAttribute('type') || '').toLowerCase(); if (tag === 'img' || (tag === 'input' && type === 'image')) { const alt = clean(el.getAttribute('alt')); if (alt) return alt; } if (tag === 'input' && ['button', 'submit', 'reset'].includes(type)) { const label = clean(el.getAttribute('value')); if (label) return label; } if (fromContent.has(role)) { const text = clean(textOf(el, 0)); if (text) return text; } return clean(el.getAttribute('title') || el.getAttribute('placeholder')); }; const visible = (el) => { const r = el.getBoundingClientRect(); if (!(r.width > 0 && r.height > 0)) return false; return typeof el.checkVisibility === 'function' ? el.checkVisibility({ opacityProperty: true, visibilityProperty: true }) : true; }; // Like ProbeRecorder.cs: the path of a link and whether it stays on the site, never the host of another site. const linkOf = (el) => { const href = el.getAttribute('href'); if (!href) return null; try { const u = new URL(href, document.baseURI); return { sito: u.origin === location.origin, path: shapeOf(u.pathname) }; } catch { return null; } }; const escapeRegex = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // User names seen in any recorded address, and every @word, become «NOME»; texts are cut to 80 characters. const mask = (text) => { if (text === null || text === undefined) return null; let out = clean(String(text)).replace(/@[\p{L}\p{N}._]+/gu, 'NOME'); for (const name of names) { out = out.replace(new RegExp('(^|[^\\p{L}\\p{N}_])' + escapeRegex(name) + '(?![\\p{L}\\p{N}_])', 'giu'), '$1NOME'); } return out.length > MAX_TEXT ? out.slice(0, MAX_TEXT) : out; }; const describe = (el, inner) => { const role = roleOf(el); const name = nameOf(el, role); const svg = el.querySelector('svg[aria-label]'); const svgLabel = svg ? clean(svg.getAttribute('aria-label')) : ''; let same = null; let position = null; if (role) { // How many visible elements share role and name, and which one this is: the «index» field of the map. same = 0; for (const other of document.querySelectorAll('*')) { if (roleOf(other) !== role || nameOf(other, role) !== name || !visible(other)) continue; if (other === el) position = same; same++; } } return { tag: el.tagName.toLowerCase(), interno: inner && inner !== el && inner.tagName ? inner.tagName.toLowerCase() : null, roleAttributo: el.getAttribute('role'), ruolo: role, ariaLabel: el.getAttribute('aria-label'), alt: el.getAttribute('alt'), titolo: el.getAttribute('title'), testo: fromContent.has(role) ? clean(el.textContent) : null, nome: name, svg: svgLabel || null, nomeDaSvg: !!svgLabel && !clean(el.getAttribute('aria-label')) && name === clean(textOf(el, 0)) && name.includes(svgLabel), collegamento: linkOf(el), tabindex: el.getAttribute('tabindex'), uguali: same, posizione: position, }; }; const onClick = (event) => { try { const inner = event.target && event.target.nodeType === 1 ? event.target : null; const el = inner && inner.closest ? inner.closest('a[href], button, [role], [tabindex]') : null; const record = { n: records.length + 1, ora: new Date().toTimeString().slice(0, 8), prima: shapeOf(location.pathname), dopo: null, elemento: el ? describe(el, inner) : null, }; records.push(record); setTimeout(() => { try { record.dopo = shapeOf(location.pathname); } catch { /* the record stays without it */ } }, 1500); console.log(`Febe: clic ${record.n} registrato${el ? '' : ' (nessun comando sotto il puntatore)'}.`); } catch { // Never disturb the page: a click that cannot be described is just not recorded. } }; document.addEventListener('click', onClick, { capture: true, passive: true }); // The records, masked, ready for bersagli..json: «» becomes «*» (one segment), «NOME» becomes «.+». const output = () => records.map((r) => { const e = r.elemento; if (!e) return { n: r.n, ora: r.ora, prima: r.prima, dopo: r.dopo, elemento: null }; const element = { ...e, roleAttributo: mask(e.roleAttributo), ariaLabel: mask(e.ariaLabel), alt: mask(e.alt), titolo: mask(e.titolo), testo: mask(e.testo), nome: mask(e.nome), svg: mask(e.svg), }; const name = element.nome ? '^' + escapeRegex(element.nome).replace(/NOME/g, '.+') + '$' : ''; return { n: r.n, ora: r.ora, prima: r.prima, dopo: r.dopo, elemento: element, perLaMappa: { role: e.ruolo, name, href: e.collegamento && e.collegamento.sito ? e.collegamento.path.replace(//g, '*') : '', index: e.posizione, }, }; }); // copy() is a utility of the DevTools Console, there while the Console runs a command: kept from the paste too. const copier = typeof copy === 'function' ? copy : null; globalThis.febeBersagli = () => { const text = JSON.stringify(output(), null, 2); let copied = true; if (typeof copy === 'function') { copy(text); } else if (copier) { copier(text); } else { copied = false; } if (copied) { console.log(`Febe: copiati negli appunti ${records.length} clic registrati. Incollali in un file di testo e controlla che non resti nessun nome.`); } else { console.log(text); console.log(`Febe: ${records.length} clic registrati, scritti qui sopra: copiali da qui.`); } return records.length; }; console.log('Febe: raccolta dei bersagli attiva (sola lettura). Naviga come al solito; alla fine scrivi febeBersagli().'); })();