Last active
September 27, 2022 15:03
-
-
Save Avaray/edbcc2a683ed5af6776dc8e8788b0308 to your computer and use it in GitHub Desktop.
[NodeJS] Playwright Starter
This file contains 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 { chromium } = require('playwright-core'); | |
// set browser to disable images loading | |
const browser = await chromium.launch({ | |
headless: true, | |
executablePath: CHROMIUM_PATH_HERE, | |
args: [ '--blink-settings=imagesEnabled=false', '--window-size=800,800' ] | |
}); | |
const page = await browser.newPage({ viewport: null }); | |
// https://playwright.dev/python/docs/api/class-request#request-resource-type | |
await page.route('**/*', route => { | |
if (route.request().resourceType() === 'stylesheet' || | |
route.request().resourceType() === 'font') { | |
route.abort(); | |
} else { route.continue() } | |
}); | |
await page.goto(URL_HERE); | |
// injecting custom CSS | |
await page.addStyleTag({path: 'YOUR_CSS_FILE.css'}); | |
await browser.close(); | |
process.exit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment