-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Screenshot is smaller than viewport setting #726
Comments
try
|
Thanks Shuichiro, this solves the screenshot size issue. El Thursday, July 14, 2016, Shuichiro Kamiya notifications@github.com
|
I don't think you can hide the scrollbars with Electron before DOM ready. Out of curiosity, could you use nightmare
.goto('http://example.com')
.evaluate(function() {
var s = document.styleSheets[0];
s.insertRule('::-webkit-scrollbar { display:none; }');
})
.viewport(100, 100)
.then(function() {
console.log('done');
}); Would something like that work for you? |
Beautiful! this seems to work! 2016-07-15 0:24 GMT-03:00 Ross Hinkley notifications@github.com:
|
Closing as this seems to be resolved. |
|
They are not documented in the readme because they are not internal to Nightmare, they're internal to Electron's What do you mean "don't appear to do anything"? |
@rosshinkley They did not auto-size the viewport to the content. Instead I had to do all of this: function calculateContentHeight() {
function getNumericalStyle(element, property) {
return parseFloat( window.getComputedStyle(element,null).getPropertyValue(property) );
}
var html = document.documentElement;
var body = document.body;
var bodyMarginBottom = getNumericalStyle(body, "margin-bottom");
var bodyMarginTop = getNumericalStyle(body, "margin-top");
var htmlMarginBottom = getNumericalStyle(html, "margin-bottom");
var htmlMarginTop = getNumericalStyle(html, "margin-top");
var bodyPaddingBottom = getNumericalStyle(body, "padding-bottom");
var bodyPaddingTop = getNumericalStyle(body, "padding-top");
var htmlPaddingBottom = getNumericalStyle(html, "padding-bottom");
var htmlPaddingTop = getNumericalStyle(html, "padding-top");
var margins = bodyMarginBottom + bodyMarginTop + htmlMarginBottom + htmlMarginTop;
var paddings = bodyPaddingBottom + bodyPaddingTop + htmlPaddingBottom + htmlPaddingTop;
return html.offsetHeight + Math.round(margins + paddings);
}
var browser = new Nightmare();
browser
.goto("etc")
.viewport(1000, 0) // for getting the actual height of short content
.then(() => browser.evaluate(calculateContentHeight))
.then(contentHeight => browser.viewport(1000, contentHeight))
.then(() => browser.wait(50)) // wait for correct calculations (?) -- Semaphore CI was failing without this, but local Ubuntu and OSX were fine
.then(() => browser.screenshot()) |
I'm trying to take an screenshot of 375x667 (in order to simulate an iPhone 6 capture) with the code below, but the screenshot is taken as a wrong size of 359x608 and also is showing scrollbar (can scrollbar be hidden?)
Enviroment:
Image Generated
Thanks,
FD
The text was updated successfully, but these errors were encountered: