Skip to content

Commit a0a9ff7

Browse files
mpstatonclaude
andcommitted
fix(linkedin-snippets): search-results accumulator survives full page loads
The snippet's accumulator was a bare window global, written when LinkedIn's Next pagination was a soft SPA navigation. Pagination now does a FULL page load (observed on the operator's capture run 2026-07-27), wiping window every page — so each run restarted the table at zero instead of appending. The accumulator now writes through to localStorage after every run and restores from it on paste, so page 2 reports "restored N rows" and keeps counting. __liClear() clears both memory and the stored copy. Usage flow unchanged: paste per page, __liDownloadCsv() when done. Files changed: - tools/browser-snippets/linkedin/linkedin-search-results-to-csv.js Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RW28dw3kQAKXr2ZNefCukE
1 parent 5c3038e commit a0a9ff7

1 file changed

Lines changed: 40 additions & 8 deletions

File tree

tools/browser-snippets/linkedin/linkedin-search-results-to-csv.js

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
// ------------
1515
// Walks every result card visible on the current page, pulls
1616
// { name, profile_url, headline, location }
17-
// for each, appends to a window-scoped accumulator (so re-running on
18-
// subsequent pages adds without losing earlier pages), de-dupes by
19-
// profile URL, and console.table()'s the running total.
17+
// for each, appends to a localStorage-backed accumulator (survives
18+
// LinkedIn's full-page-load pagination — re-running on subsequent pages
19+
// adds without losing earlier pages), de-dupes by profile URL, and
20+
// console.table()'s the running total.
2021
//
2122
// Call window.__liDownloadCsv() at any point to download the accumulated
2223
// rows as a CSV. Call window.__liClear() to start over.
@@ -64,15 +65,40 @@
6465
// default and the original snippet's console.info lines were invisible.)
6566
const log = (...args) => console.error('[li-scrape]', ...args);
6667

67-
// ---- ACCUMULATOR — SURVIVES ACROSS RE-RUNS ON LATER PAGES --------------
68+
// ---- ACCUMULATOR — SURVIVES ACROSS RE-RUNS *AND* FULL PAGE LOADS -------
69+
// Originally a bare window global, which only survives soft (SPA)
70+
// navigations — but LinkedIn's Next pagination does a FULL page load,
71+
// wiping window and restarting the table every run (observed 2026-07-27).
72+
// localStorage survives reloads on the same origin; the window object is
73+
// kept as a same-context mirror. __liClear() removes the stored copy.
74+
const STORE_KEY = 'li-scrape-accumulator';
6875
if (!window.__liScrape) {
76+
let stored = null;
77+
try {
78+
stored = JSON.parse(localStorage.getItem(STORE_KEY) || 'null');
79+
} catch {
80+
/* corrupt store → start fresh */
81+
}
6982
window.__liScrape = {
70-
rows: [],
71-
seenUrls: new Set(),
72-
pagesSeen: 0,
83+
rows: stored?.rows ?? [],
84+
seenUrls: new Set((stored?.rows ?? []).map((r) => r.profile_url)),
85+
pagesSeen: stored?.pagesSeen ?? 0,
7386
};
87+
if (stored?.rows?.length) {
88+
log(`restored ${stored.rows.length} rows from a previous page load.`);
89+
}
7490
}
7591
const acc = window.__liScrape;
92+
const persist = () => {
93+
try {
94+
localStorage.setItem(
95+
STORE_KEY,
96+
JSON.stringify({ rows: acc.rows, pagesSeen: acc.pagesSeen }),
97+
);
98+
} catch (e) {
99+
log('warning: could not persist accumulator —', e?.message);
100+
}
101+
};
76102

77103
// ---- HELPERS -----------------------------------------------------------
78104
const cleanText = (s) =>
@@ -185,6 +211,7 @@
185211
acc.seenUrls.add(profile_url);
186212
}
187213
acc.pagesSeen += 1;
214+
persist();
188215

189216
// ---- REPORT ------------------------------------------------------------
190217
log(
@@ -227,7 +254,12 @@
227254
if (!window.__liClear) {
228255
window.__liClear = () => {
229256
window.__liScrape = { rows: [], seenUrls: new Set(), pagesSeen: 0 };
230-
console.error('[li-scrape] accumulator cleared.');
257+
try {
258+
localStorage.removeItem('li-scrape-accumulator');
259+
} catch {
260+
/* nothing stored */
261+
}
262+
console.error('[li-scrape] accumulator cleared (memory + localStorage).');
231263
};
232264
}
233265
})();

0 commit comments

Comments
 (0)