Run with just width and not height
vid-pas opened this issue · 2 comments
I've noticed that if I run the command with just width and no height, width is ignored.
From line 41: if (program.w && program.h) await page.setViewport({width: Number(program.w), height: Number(program.h)})
If I run it with a specified width, and height 0, I do get the specified width.
So the user can get around this but a nice addition might be to set h to 0 if it's unset.
Maybe something like this
diff --git a/index.js b/index.js
index 40f5b02..cb7b821 100755
--- a/index.js
+++ b/index.js
@@ -38,7 +38,8 @@ console.log(fullPage);
const browser = await puppeteer.launch()
const page = await browser.newPage()
const d = new Date()
- if (program.w && program.h) await page.setViewport({width: Number(program.w), height: Number(program.h)})
+ const height = !program.h?0:program.h;
+ if (program.w && height) await page.setViewport({width: Number(program.w), height: Number(height)})
if (program.emulate) await page.emulate(devices[program.emulate]);
await page.goto(urlvalue)
const title = await page.title()
@vid-pas May I know what is your use case for this?
The width and height are like the browser size, the default size is 600
. You can try to give it 600
, I don't see why people want to set it to 0
.
P.S. if you are using emulate
or fullpage
, the height doesn't really matter.
Sure. Since the default is fullpage=true; I want to specify a width and get a screenshot with my width and full page.
Right now I only achieve this with --h 0
--h 0
is a work around, it's used so that the code respects the --w
arg.