Last active
December 3, 2020 16:48
-
-
Save ArturMiguel/b47ec60e292d2403da44f77bdd079c0d to your computer and use it in GitHub Desktop.
Block resource request in Puppeteer to otimize page loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const blockedResources = [ | |
| 'stylesheet', | |
| 'image', | |
| 'media', | |
| 'font', | |
| 'texttrack', | |
| 'xhr', | |
| 'fetch', | |
| 'eventsource', | |
| 'websocket', | |
| 'manifest', | |
| 'other' | |
| ]; | |
| await page.setRequestInterception(true); | |
| page.on('request', (request) => { | |
| if (blockedResources.includes(request.resourceType())) { | |
| request.abort(); | |
| } else { | |
| request.continue(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment