Skip to content

Instantly share code, notes, and snippets.

@Avaray
Last active September 27, 2022 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Avaray/edbcc2a683ed5af6776dc8e8788b0308 to your computer and use it in GitHub Desktop.
Save Avaray/edbcc2a683ed5af6776dc8e8788b0308 to your computer and use it in GitHub Desktop.
[NodeJS] Playwright Starter
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