Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cdp-screenshot

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cdp-screenshot

chrome headless 通用截图引擎。

  • 0.1.1-1
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

cdp-screenshot

chrome headless 通用截图引擎。

安装

命令行安装

npm i -g cdp-screenshot

安装源码包

npm i -S cdp-screenshot

命令

如下图:

帮助命令

自定义

继承截图类

import CDPScreenshot from 'cdp-screenshot';

class MyCDPScreenshot extends CDPScreenshot {
}

自定义属性

  /**
   * 需要注入CDP的js源码路径
   */
  injectedCodePaths = [] as string[];

  /**
   * 要访问的 url
   */
  url = 'http://www.taobao.com';

  /**
   * 截图的文件位置
   */
  scotFilename = 'scot.png';

  /**
   * 截图的宽度
   */
  viewportWidth = 900;

  /**
   * 截图的高度
   */
  viewportHeight = 400;

  /**
   * 打印格式
   * PNG or PDF
   */
  format = CDPScreenshotFormat.PNG;

自定义生命周期

  /**
   * 访问页面 url 之后。页面资源加载之前。
   */
  didPageNavigated() {
  }

  /**
   * 页面加载完毕,将要进行截图之前
   */
  async willScreenshot() {
  }
  
  /**
   * 进行截图
   */
  async screenshot() {
    if (this.format === CDPScreenshotFormat.PNG) {
      await this.screenshotPng();
    } else {
      await this.screenshotPDF();
    }
  }

  /**
   * 截图之后
   */
  async didScreenshot() {
  }

帮助方法

  /**
   * 在 CDP 中执行函数
   * 
   * @param func 函数引用
   * @param args 函数参数
   */
  async injectFunction(func: any, ...args: any[]) {
  }
  
  /**
   * 在 CDP 中执行返回 Promise 的函数,函数执行会被阻塞
   * 
   * @param func 函数引用
   * @param args 函数参数
   */
  async injectPromiseFunction(func: any, ...args: any[]) {
  }
  
  /**
   * 注入源码,返回源码表达式返回值
   * @param code 源码
   */
  async injectCode(code: string) {
  }

  /**
   * 注入js表达式源码,表达式返回值为 promise,函数执行会被阻塞。
   *
   * @param code 源码
   */
  async injectPromiseCode(code: string) {
    return await this.client.Runtime.evaluate({
      expression: code,
      awaitPromise: true,
    });
  }


执行截图

const myClient = new MyCDPScreenshot();

myClient.run();

FAQs

Package last updated on 26 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc