Instagram: Febe legge le risposte vere (campioni dal HAR del 21/10)
Febe non estraeva nulla da Instagram per due motivi. Instagram manda i dati di storie e raccolte (GraphQL) come text/javascript, e la cattura leggeva solo le risposte dichiarate JSON: le scartava tutte. E i file di Instagram (lettori, bersagli) erano scheletri, quindi le ricette si rifiutavano di girare. Alberto ha mandato un HAR del suo browser e una guida. La guida descrive richieste costruite a mano, vietate dalle regole 2-4, e un formato che nel HAR non compare: non si usa. Dal HAR si è letta solo la forma; le risposte utili sono diventate campioni grezzi fuori dal repository, ripuliti e verificati con febe-sonda (tests/Febe.Tests/campioni/instagram). Che cosa cambia: - la cattura legge le risposte text/javascript chieste dalla pagina (mai gli script) e ogni blocco JSON incorporato nel documento della pagina, e avvisa quando un corpo atteso non arriverà; - le risposte che non parlano di contenuti (promozioni, «storia vista») si ignorano invece di valere come formato non riconosciuto; - lettori.instagram.json è confermato, con sole chiavi presenti nei campioni; identificativi delle raccolte nella forma dell'indirizzo; - bersagli.instagram.json ha le pagine viste nel traffico vero; i bersagli restano vuoti (H11): storie, raccolte, Taggati e Reel aspettano lo script tools/bersagli/raccogli-bersagli.js; - le ricette del profilo reggono dati in risposte diverse e prendono la paginazione solo dalla risposta che porta i loro post; l'elenco dei seguiti scarta i profili suggeriti; «Tu» si riconosce anche dal solo identificativo dell'account collegato; - il visualizzatore delle raccolte conta i contenuti (l'indirizzo non cambia), chiede il permesso prima di ogni contenuto e si chiude sempre; - una ricetta che la configurazione non lascia girare è «Da configurare»: non è un guasto, non si sospende, non si pianifica; le sospensioni dovute ai file vecchi si azzerano una volta al cambio dei file; - la barra laterale dice «Collegato» dal cookie di sessione; i «Post singolo» per gli indirizzi scaduti non vengono più annullati; - febe-sonda da-har; la ripulitura tiene latest_reel_media e mette un riempitivo neutro sotto le chiavi simili a segreti (gitleaks). Prove su Windows: 783 superate, 76 saltate (Chromium e Xvfb, nella CI). Nulla è stato provato contro Instagram. Dettagli e decisioni in docs/stato.md e docs/decisioni.md (righe del 25 ottobre). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b3a7c31e5a
commit
31bbbf8bb7
69 files changed
+9184
-453
No files matched your search
@@ -0,0 +1,33 @@
|
||||
# Raccolta dei bersagli dal browser di tutti i giorni
|
||||
|
||||
`raccogli-bersagli.js` serve a compilare i **bersagli** di `src/Febe.Core/Config/bersagli.instagram.json` (ipotesi
|
||||
H11): l'anello delle storie, la zona «avanti» e la X del visualizzatore, le schede del profilo, le raccolte in evidenza.
|
||||
Si usa come spiegato in `docs/prove-dal-vivo.md`, parte **A bis**.
|
||||
|
||||
## Come si usa
|
||||
|
||||
1. Nel browser con cui navighi di solito, già entrato nel sito, apri gli strumenti per sviluppatori (F12) e la scheda
|
||||
**Console**.
|
||||
2. Incolla tutto il contenuto di `raccogli-bersagli.js` e premi Invio. Compare «Febe: raccolta dei bersagli attiva».
|
||||
Se la pagina si ricarica del tutto, la raccolta si perde: incollalo di nuovo.
|
||||
3. Naviga e clicca come al solito. A ogni clic la Console scrive «Febe: clic N registrato».
|
||||
4. Alla fine scrivi `febeBersagli()` nella Console: copia negli appunti i clic registrati (se la copia non riesce, li
|
||||
scrive nella Console e li copi da lì).
|
||||
|
||||
## Che cosa fa e che cosa non fa
|
||||
|
||||
- **Sola lettura.** Aggiunge un solo ascoltatore dei clic, che non blocca e non cambia il clic, e legge attributi.
|
||||
Non modifica la pagina, non manda nulla a nessuno, non legge cookie né le memorie del browser. I dati restano nella
|
||||
memoria della scheda finché non chiami `febeBersagli()`.
|
||||
- Per ogni clic registra la forma dell'indirizzo prima e circa 1,5 secondi dopo, e del comando cliccato (il più vicino
|
||||
fra collegamento, pulsante, elemento con un ruolo o con `tabindex`): elemento, ruolo, `aria-label`, `alt`, `title`, il
|
||||
testo (solo per pulsanti, collegamenti, schede e simili), il **nome accessibile calcolato come lo calcola Febe**
|
||||
(`src/Febe.Browser/Targets/TargetResolver.cs`), se il nome viene da un'icona `svg` con `aria-label`, la forma del
|
||||
collegamento, e quanti elementi visibili hanno lo stesso ruolo e lo stesso nome (con la posizione di quello cliccato).
|
||||
- La voce `perLaMappa` è già nella forma dei campi `role`, `name`, `href` e `index` della mappa.
|
||||
- **Nomi.** Negli indirizzi restano solo le parole fisse (`stories`, `highlights`, `p`, `reel`, `reels`, `tagged`,
|
||||
`following`, `followers`, `explore`); ogni altro pezzo diventa `<x>`. Nei testi registrati, i nomi visti negli
|
||||
indirizzi e ogni `@parola` diventano `NOME`. I nomi scritti per esteso (per esempio «Mario Rossi») **non** si
|
||||
riconoscono: prima di inviare il testo, sostituisci a mano con `NOME` ogni nome di persona rimasto.
|
||||
- Un nome utente che è anche una parola dell'interfaccia può far diventare `NOME` anche quella parola: va bene così,
|
||||
meglio un nome di comando in meno che un nome di persona in più.
|
||||
@@ -0,0 +1,258 @@
|
||||
// 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.<sito>.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 «<x>»; 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 «<x>». 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 '<x>';
|
||||
}).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.<sito>.json: «<x>» 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(/<x>/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().');
|
||||
})();
|
||||
Reference in new issue
Block a user