miniprogram-automator 截图失败
发布于 7 年前 作者 tjin 14772 次浏览 来自 官方Issues

确定开发环境没有问题,因为本来可以截图,后来突然开始报错,重启开发者工具甚至重启电脑都没用。使用 node repl 就可以复现,但只在我的电脑上有问题,由于问题与代码无关,无法提供复现步骤。

报错内容:Error: fail to capture screenshot 操作步骤与详细报错如下。

> const automator = require('miniprogram-automator')
undefined
> automator.launch({
... projectPath:
... '/Users/username/dev/wxa-dcp/dist'
... }).then(mpp => global.mpp = mpp)
Promise { <pending> }

# 不带 options 报错

> mpp.screenshot()
Promise { <pending> }
> (node:4886) UnhandledPromiseRejectionWarning: Error: fail to capture screenshot
    at Transport.Connection.onMessage (/Users/username/dev/temp/test-project/node_modules/miniprogram-automator/out/Connection.js:1:986)
    at Transport.emit (events.js:315:20)
    at Transport.EventEmitter.emit (domain.js:505:15)
    at WebSocket.<anonymous> (/Users/username/dev/temp/test-project/node_modules/miniprogram-automator/out/Transport.js:1:219)
    at WebSocket.onMessage (/Users/username/dev/temp/test-project/node_modules/miniprogram-automator/node_modules/ws/lib/event-target.js:120:16)
    at WebSocket.emit (events.js:315:20)
    at WebSocket.EventEmitter.emit (domain.js:505:15)
    at Receiver.receiverOnMessage (/Users/username/dev/temp/test-project/node_modules/miniprogram-automator/node_modules/ws/lib/websocket.js:789:20)
    at Receiver.emit (events.js:315:20)
    at Receiver.EventEmitter.emit (domain.js:505:15)
(node:4886) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:4886) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

# 带 options 也报错,指定目录无权限问题

> mpp.screenshot({path: '/Users/username/Desktop/aaa.png'})
Promise { <pending> }
> (node:4886) UnhandledPromiseRejectionWarning: Error: fail to capture screenshot
    at Transport.Connection.onMessage (/Users/username/dev/temp/test-project/node_modules/miniprogram-automator/out/Connection.js:1:986)
    at Transport.emit (events.js:315:20)
    at Transport.EventEmitter.emit (domain.js:505:15)
    at WebSocket.<anonymous> (/Users/username/dev/temp/test-project/node_modules/miniprogram-automator/out/Transport.js:1:219)
    at WebSocket.onMessage (/Users/username/dev/temp/test-project/node_modules/miniprogram-automator/node_modules/ws/lib/event-target.js:120:16)
    at WebSocket.emit (events.js:315:20)
    at WebSocket.EventEmitter.emit (domain.js:505:15)
    at Receiver.receiverOnMessage (/Users/zhangchaofan/dev/temp/test-project/node_modules/miniprogram-automator/node_modules/ws/lib/websocket.js:789:20)
    at Receiver.emit (events.js:315:20)
    at Receiver.EventEmitter.emit (domain.js:505:15)
(node:4886) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
1 回复

基础库版本是什么?清除工具缓存试下

回到顶部