export-html icon indicating copy to clipboard operation
export-html copied to clipboard

viewport size fixed to default: 800x600

Open a-marcellini opened this issue 3 years ago • 0 comments

Hi, Trying to crop an html page I found that although I can specify the clip parameters, I cannot specify the viewport size:

{
  "html": "...",
  "export": {
		"type": "png",
		"fullPage": "false",
		"scale": 2,
		"clip": {
			"x": 1,
			"y": 1,
			"width": 1400,
			"height": 900
		}
  }
}	

Then the service create an image with 1440 wide, but in fact it is an 800 wide image "filled" to reach 1400. The reason is that the puppeteer should have been launched with a consistent viewport size, like as an example:

 browser = await puppeteer.launch({
    defaultViewport: {
        width: 1400,
        height: 900
    }
})

In case defaultViewport is not specified, puppeteer will use the default 800x600 size.

Otherwise you could adapt the viewport to the size of the clipping area:

  if ( !body.export.fullPage && body.export.clip !== null && body.export.clip !== undefined &&
         (body.export.clip.width > page.viewport().width || body.export.clip.height > page.viewport().height) ) {

      await page.setViewport({ width: body.export.clip.width, height: body.export.clip.height});

  }

a-marcellini avatar Oct 26 '22 15:10 a-marcellini