Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run with just width and not height #12

Closed
vid-pas opened this issue Dec 5, 2018 · 2 comments
Closed

Run with just width and not height #12

vid-pas opened this issue Dec 5, 2018 · 2 comments

Comments

@vid-pas
Copy link
Contributor

vid-pas commented Dec 5, 2018

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()
@cylim
Copy link

cylim commented Dec 7, 2018

@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.

@vid-pas
Copy link
Contributor Author

vid-pas commented Dec 8, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants