Remove images and CSS from crawled pages
Some checks failed
GBCI / build (push) Failing after 16m12s
Some checks failed
GBCI / build (push) Failing after 16m12s
This commit is contained in:
parent
d6b6d4c09f
commit
c9612fcf23
1 changed files with 17 additions and 8 deletions
|
|
@ -1208,14 +1208,23 @@ export class KBService implements IGBKBService {
|
||||||
await min.core['setConfig'](min, 'Color1', colors[0].hex());
|
await min.core['setConfig'](min, 'Color1', colors[0].hex());
|
||||||
await min.core['setConfig'](min, 'Color2', colors[1].hex());
|
await min.core['setConfig'](min, 'Color2', colors[1].hex());
|
||||||
}
|
}
|
||||||
// Disables images in crawling.
|
|
||||||
await page.route('**/*', route => {
|
// Remove images and disable CSS after page loads
|
||||||
const type = route.request().resourceType();
|
await page.evaluate(() => {
|
||||||
if (type === 'image' || type === 'stylesheet') {
|
// Remove all images
|
||||||
route.abort();
|
document.querySelectorAll('img').forEach(img => img.remove());
|
||||||
} else {
|
|
||||||
route.continue();
|
// Disable all stylesheets
|
||||||
}
|
document.querySelectorAll('link[rel="stylesheet"]').forEach(link => {
|
||||||
|
link['disabled'] = true;
|
||||||
|
link.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Remove inline styles
|
||||||
|
document.querySelectorAll('style').forEach(style => style.remove());
|
||||||
|
|
||||||
|
// Remove style attributes
|
||||||
|
document.querySelectorAll('[style]').forEach(el => el.removeAttribute('style'));
|
||||||
});
|
});
|
||||||
|
|
||||||
page.on('dialog', async dialog => {
|
page.on('dialog', async dialog => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue