(page: Page | Frame)
| 162 | * Exported for DRY reuse in meta-commands (diff). |
| 163 | */ |
| 164 | export 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 |
no test coverage detected