|
@@ -172,8 +172,12 @@ class Webshot extends CallableInstance<[Tweet[], (...args) => void, number], Pro
|
|
|
})
|
|
|
.then(handle => {
|
|
|
if (handle === null) throw new puppeteer.errors.TimeoutError();
|
|
|
+ let cropTop: number;
|
|
|
return chainPromises(morePostProcessings.map(func => () => func(page, handle)))
|
|
|
.then(() => promisify(setTimeout)(getTimeout()))
|
|
|
+ // determine screenshot crop y offset
|
|
|
+ .then(() => page.evaluate(() => document.documentElement.scrollTop))
|
|
|
+ .then(scrollTop => { cropTop = scrollTop * zoomFactor; })
|
|
|
// hide highlight of retweet header
|
|
|
.then(() => page.evaluate(() => (document.activeElement as unknown as HTMLOrSVGElement).blur()))
|
|
|
// determine screenshot height
|
|
@@ -187,16 +191,23 @@ class Webshot extends CallableInstance<[Tweet[], (...args) => void, number], Pro
|
|
|
logger.error(`error while parsing content height, failing this webshot`);
|
|
|
throw err;
|
|
|
})
|
|
|
- .then(parentDivHandle => parentDivHandle.screenshot());
|
|
|
+ .then(parentDivHandle => parentDivHandle.screenshot())
|
|
|
+ .then<[Buffer, number]>(screenshot => [screenshot, cropTop]);
|
|
|
})
|
|
|
- .then(screenshot => {
|
|
|
+ .then(([screenshot, cropTop]) => {
|
|
|
new PNG({
|
|
|
filterType: 4,
|
|
|
deflateLevel: 0,
|
|
|
}).on('parsed', function () {
|
|
|
- sharpToFile(jpeg(this.pack())).then(path => {
|
|
|
+ let png = this;
|
|
|
+ if (cropTop > 0) {
|
|
|
+ logger.info(`cropping screenshot at y offset ${cropTop}...`);
|
|
|
+ png = new PNG({width: this.width, height: this.height - cropTop});
|
|
|
+ this.bitblt(png, 0, cropTop, png.width, png.height, 0, 0);
|
|
|
+ }
|
|
|
+ sharpToFile(jpeg(png.pack())).then(path => {
|
|
|
logger.info(`finished webshot for ${url}`);
|
|
|
- resolve({path, boundary: this.height});
|
|
|
+ resolve({path, boundary: png.height});
|
|
|
});
|
|
|
}).parse(screenshot);
|
|
|
})
|