Skip to content

viewport size fixed to default: 800x600 #5

@a-marcellini

Description

@a-marcellini

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});

  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions