Code Monkey home page Code Monkey logo

snap's Introduction

环境依赖

本地运行

  • 启动

    npm run node-debug
  • 地址

    http://127.0.0.1:3000/api/shot?url=https%3A%2F%2Fwww.baidu.com%2F

线上部署

  • PM2
    npm run deploy

接口文档

  • 参数

    属性 类型 默认值 必填 说明
    src / source 调用方 标识
    callback JSONP 回调函数,不传为非 JSONP 请求
    cache 0 是否启用缓存,1是0否
    type data 返回类型,data文件url链接
    resheaders Response Headers,当 type == "data" 时生效
    url urls/url必有其一,待截图页面链接,GET请求需进行 urlencode
    name 截图名称,当 type == "data" 时生效
    c / cookies 待截图页面COOKIES,[{"name": "name", "value": "value", "domain": "domain"}],GET请求需进行 JSON.stringfy 和 urlencode
    urls urls/url必有其一,待截图页面链接,GET请求需进行 JSON.stringfy 和 urlencode
    - urls.url 待截图页面链接
    - urls.name 截图名称
    - urls.cookies 待截图页面COOKIES
    s 待截图页面元素,GET请求需进行 urlencode
    m 0 是否为移动端,1是0否,为移动端时,模拟器为 iPhone 6
    device iPhone 6 移动端模拟器,默认 iPhone 6,当 m == 1 时生效,模拟器列表参考:https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts
    f 1 是否全屏截屏,1是0否,为1时全屏高度貌似为html元素的高度
    fs 获取全屏宽高页面元素,默认 document.body.scrollWidth/document.body.scrollHeight
    x 0 截屏左上角x坐标
    y 0 截屏左上角y坐标
    w 截屏宽度
    h 截屏高度
    t 500 预留页面渲染时间,单位为毫秒(ms)
    ts 0 截图当前时间戳
    scale 1 页面的缩放(可以认为是 dpr)
    snapType png 截图图片类型,jpeg/png,默认png
    snapQuality 1 截图图片质量,0-100,默认100,当 snapType == "jpeg" 时生效
    preActions 开始截图前,页面操作,GET请求需进行 JSON.stringfy 和 urlencode
    - action.event 开始截图前,页面操作类型,支持类型:init(初始化)/click(点击)/tap(移动端点击)/back(返回)/wait(停留)/drag(拖拽)
    - action.selector 开始截图前,页面操作元素,->click
    - action.xy 开始截图前,页面拖拽坐标,[[100, 100], [100, 10], [200, 10], ...],->click/drag
    - action.time 开始截图前,页面操作后,预留页面渲染时间,单位为毫秒(ms)
    actions 页面操作,GET请求需进行 JSON.stringfy 和 urlencode
    - action.event 页面操作类型,支持类型:init(初始化)/click(点击)/tap(移动端点击)/back(返回)/wait(停留)/drag(拖拽)
    - action.selector 页面操作元素,->click
    - action.xy 页面拖拽坐标,[[100, 100], [100, 10], [200, 10], ...],->click/drag
    - action.time 页面操作后,预留页面渲染时间,单位为毫秒(ms)
    - action.s 页面操作后,截图元素
    - action.name 页面操作后,截图名称
    - action.snap 页面操作后,是否截图,1是0否,默认1
    - action.html 页面操作后,是否保存页面,1是0否,默认0
  • 调用

    • GET or POST or JSONP
    • Content-Type 支持
      • application/json
      • application/x-www-form-urlencoded

注意事项

  • 全屏截屏

    page.screenshot({
      fullPage: true
    });
    • 全屏高度貌似为html元素的高度
    • 元素勿使用 height: 100% 之类的属性
  • 选择器截图

    • 当触发 page.setViewport(viewport)
    • 页面重绘可能会导致页面错乱
    • 尽量最初就设置 viewport 为合适的值,以防触发重绘

TODO

  • 功能类

    • 调用数据存储 √
    • 调用数据统计 √
    • 图片上传S3
    • 过期本地图片
    • 支持截图名称 √
    • 支持RPC调用
    • 支持异步回调
    • 支持主动查询 √
    • 支持Websocket推送
  • 优化类

    • 截图失败重试 √
    • type=data占位图
    • 截小图拼大图 √
    • 优化异常处理 √
    • 批量并发处理
    • 截小图并发处理
    • 封装请求参数 √
    • 封装返回函数 √
    • 系统日志优化
  • 部署类

    • 生成Docker镜像

Why’s The Design

版本记录

CHANGELOG

License

MIT

Copyright(c) 2021 Lianjia, Inc. All Rights Reserved

snap's People

Contributors

brightcells avatar happytinafu avatar

Stargazers

markidos avatar  avatar  avatar  avatar  avatar MHC-I avatar Finch UI avatar AkagiYui avatar  avatar  avatar  avatar wuxiao avatar FSECD avatar 无重力广场 avatar Yu avatar uncle avatar daisenrong avatar Yuchen Wang avatar  avatar  avatar  avatar cestoon avatar saksim avatar ywc avatar  avatar  avatar Chrischien avatar Leon Zhang avatar  avatar chenliu avatar  avatar  avatar leayn03 avatar  avatar

Watchers

James Cloos avatar James Li avatar Aaaaaaaaaah. avatar Ethan avatar HermanLiu avatar 大董 avatar Leon Zhang avatar Jay avatar  avatar baoyinli avatar caofenze avatar  avatar  avatar vito avatar  avatar Tom avatar tangfuling avatar  avatar 小鄧子 avatar  avatar

snap's Issues

部署完成后,出现 no such file or directory 是要先截图吗?

ENOENT: no such file or directory, stat '/home/runner/snap/ke-snap/public/media/24e27a89b39cebd2c415d1bc9be5953a.png'
404
Error: ENOENT: no such file or directory, stat '/home/runner/snap/ke-snap/public/media/24e27a89b39cebd2c415d1bc9be5953a.png'

请问该怎么截图,使用浏览器访问的话。

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.