## 网页截图lib


## 网页截图任务参数

```json
{
  "pageUrl": "https://google.com", //需要截图的目标页面完整URL,
  "timeToPageLoad": 3000, //非必填, 在截图前的等待时间单位毫秒，用于等待页面渲染完毕。默认值3000
  "cookies": [ //非必填, 需要设置的cookie列表，例如需要进行鉴权登录的页面，设置登录cookie
    { 
      "name": 'access-token',
      "value": "",
      "domain": "test.com",
      "secure": true, //非必填
      "path": "/", //非必填
      "sameSite": "None" //非必填
    }
  ],
  "mode": "elementBase", // 截图模式：elementBase(基于元素), viewportBase(基于可视区域)
  "screenshotSetting": {  //非必填,截图设置, 部分参数可参照：https://pptr.dev/#?product=Puppeteer&version=v11.0.0&show=api-pagescreenshotoptions
    "type": "png",  // 默认值： jpeg
    "quality": 100, // 默认值：100
    "omitBackground": false, // 默认值： false
    "encoding": "binary", // 默认值：binary
  },
  "modeSetting": {
    "elementBase": { // 只需要设定需要截取的元素
      "elementSelector": "#element-id",
      "viewportWidth": 200, // 默认值：1024
      "viewportHeight": 400, // 默认值：800 
      "offset": { //非必填 截取元素内区域，通过指定，区域四边对应元素边界的偏移量设置
        "top": 10, // 默认值：0
        "left": 10, // 默认值：0
        "right": 10, // 默认值：0
        "bottom": 10 // 默认值：0
      }
    },
    "viewportBase": { // custom 模式, 通过定义视窗大小，和要截取的区域，进行截图
      "viewportWidth": 200,// 默认值：1024
      "viewportHeight": 400, // 默认值：800
      "fullPage": false, // 是否截取viewport以外的scroll区域, 默认值：false
      "clip": { //非必填 截图区域
        "x": 10,
        "y": 10,
        "width": 200,
        "height": 200
      }
    }
  }
}
```

### 相关依赖

1. ts类型定义转json-schema: https://github.com/YousefED/typescript-json-schema
2. 获取json-schema中默认值: https://www.npmjs.com/package/json-schema-defaults
3. Puppeteer 浏览器node库: https://pptr.dev
