Adding new --no exclude parameter

This commit is contained in:
Vladimir Carrer 2018-12-14 12:23:49 +01:00
parent eb1dfc8f21
commit 04a67c82d0
3 changed files with 17 additions and 2 deletions

View file

@ -36,6 +36,7 @@ Parameters:
--waitfor - wait time for the page load in milliseconds --waitfor - wait time for the page load in milliseconds
--el - css selector document.querySelector --el - css selector document.querySelector
--auth - basic http authentication --auth - basic http authentication
--no - exclude "image", "stylesheet", "script", "font"
<p> <p>
@ -60,6 +61,10 @@ screenshoteer --url https://news.ycombinator.com/item?id=18598672 --el ".fatite
screenshoteer --url https://site.com --auth "username;password" screenshoteer --url https://site.com --auth "username;password"
screenshoteer --url https://www.nytimes.com --no "image"
screenshoteer --url https://www.nytimes.com --no "script"
screenshoteer --url file:///Users/../index.html screenshoteer --url file:///Users/../index.html
``` ```
<p> List of of supported mobile devices: https://github.com/GoogleChrome/puppeteer/blob/master/DeviceDescriptors.js <p> List of of supported mobile devices: https://github.com/GoogleChrome/puppeteer/blob/master/DeviceDescriptors.js

View file

@ -14,6 +14,7 @@ program
.option('--waitfor, [waitfor]', 'Wait time in milliseconds') .option('--waitfor, [waitfor]', 'Wait time in milliseconds')
.option('--el, [el]', 'element css selector') .option('--el, [el]', 'element css selector')
.option('--auth, [auth]', 'Basic HTTP authentication') .option('--auth, [auth]', 'Basic HTTP authentication')
.option('--no, [no]', 'Exclude')
.parse(process.argv); .parse(process.argv);
if (!program.url) { if (!program.url) {
@ -38,6 +39,15 @@ console.log(program.fullPage);
async function execute() { async function execute() {
const browser = await puppeteer.launch(); const browser = await puppeteer.launch();
const page = await browser.newPage(); const page = await browser.newPage();
if (program.no) {
await page.setRequestInterception(true);
page.on('request', request => {
if (request.resourceType() === program.no)
request.abort();
else
request.continue();
});
}
const timestamp = new Date().getTime(); const timestamp = new Date().getTime();
if (program.w || program.h) { if (program.w || program.h) {
const newWidth = !program.w?600:program.w const newWidth = !program.w?600:program.w

View file

@ -1,6 +1,6 @@
{ {
"name": "screenshoteer", "name": "screenshoteer",
"version": "1.0.5", "version": "1.0.6",
"description": "Make screenshots and device emulations form your terminal", "description": "Make screenshots and device emulations form your terminal",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {