MCPcopy
hub / github.com/garrytan/gstack / getCleanText

Function getCleanText

browse/src/read-commands.ts:164–177  ·  view source on GitHub ↗
(page: Page | Frame)

Source from the content-addressed store, hash-verified

162 * Exported for DRY reuse in meta-commands (diff).
163 */
164export async function getCleanText(page: Page | Frame): Promise<string> {
165 const raw = await page.evaluate(() => {
166 const body = document.body;
167 if (!body) return '';
168 const clone = body.cloneNode(true) as HTMLElement;
169 clone.querySelectorAll('script, style, noscript, svg').forEach(el => el.remove());
170 return clone.innerText
171 .split('\n')
172 .map(line => line.trim())
173 .filter(line => line.length > 0)
174 .join('\n');
175 });
176 return stripLoneSurrogates(raw);
177}
178
179/**
180 * When cookies have been imported for specific domains, block JS execution

Callers 2

handleMetaCommandFunction · 0.90
handleReadCommandFunction · 0.85

Calls 1

stripLoneSurrogatesFunction · 0.90

Tested by

no test coverage detected