auto-chrome
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -122,6 +122,15 @@ "use strict"; | ||
// await this.send('Browser.close'); | ||
await this.send('Browser.close').then(data => { | ||
this.process.kill(); | ||
// 返回错位消息时,强制退出chrome进程 | ||
if (data.error) { | ||
logger.warn('Browser.close消息响应超时,强制退出进程'); | ||
this.process.kill(); | ||
} | ||
}) | ||
} | ||
@@ -128,0 +137,0 @@ } |
@@ -30,8 +30,7 @@ "use strict"; | ||
const id = this.id++ | ||
const id = this.id++; | ||
const message = { id, method, params } | ||
const message = JSON.stringify({ id, method, params }); | ||
// 发送消息 | ||
this.ws.send(JSON.stringify(message)); | ||
this.ws.send(message); // 发送消息 | ||
@@ -43,3 +42,4 @@ return new Promise((resolve, reject) => { | ||
logger.error(error); | ||
}) | ||
return { error }; | ||
}); | ||
@@ -54,8 +54,10 @@ } | ||
const { id } = message; | ||
// 带id为主动消息 | ||
if (message.id) { | ||
if (id) { | ||
let { id, result, error } = message | ||
const { result, error } = message; | ||
const callback = this.callbacks.get(id) | ||
const callback = this.callbacks.get(id); | ||
@@ -66,3 +68,3 @@ if (callback) { | ||
if (error) { | ||
callback.reject(error) | ||
callback.reject(error); | ||
} else { | ||
@@ -78,8 +80,8 @@ callback.resolve(result); | ||
let { method, params } = message | ||
const { method, params } = message; | ||
// 带sessionId的Target子消息 | ||
if (method === 'Target.receivedMessageFromTarget') { | ||
let { targetId, message } = params | ||
let page = this.pages.get(targetId) | ||
const { targetId, message } = params; | ||
const page = this.pages.get(targetId); | ||
if (page) { | ||
@@ -90,3 +92,3 @@ page.message(message); | ||
if (this[method]) { | ||
this[method](params) | ||
this[method](params); | ||
} | ||
@@ -93,0 +95,0 @@ } |
@@ -7,3 +7,3 @@ "use strict"; | ||
const timechain = new timeChain({ delay: 10000 }) | ||
const timechain = new timeChain({ delay: 10000 }); | ||
@@ -10,0 +10,0 @@ module.exports = { |
{ | ||
"name": "auto-chrome", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "使用Node.js操作Chrome或Chromium,高仿真的用户行为模拟器", | ||
@@ -5,0 +5,0 @@ "main": "lib/", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82911
1948