Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
5e9c6715
W
wechaty
项目概览
.Veneno.
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5e9c6715
编写于
10月 17, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
#51
上级
3ae7a4a9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
67 deletion
+45
-67
src/puppet-web/browser.ts
src/puppet-web/browser.ts
+10
-15
src/puppet-web/event.ts
src/puppet-web/event.ts
+35
-52
未找到文件。
src/puppet-web/browser.ts
浏览文件 @
5e9c6715
...
...
@@ -95,17 +95,9 @@ class Browser extends EventEmitter {
return
this
}
catch
(
e
)
{
// .catch(e => {
// XXX: must has a `.catch` here, or promise will hang! 2016/6/7
// XXX: if no `.catch` here, promise will hang!
// with selenium-webdriver v2.53.2
// XXX: https://github.com/SeleniumHQ/selenium/issues/2233
log
.
error
(
'
PuppetWebBrowser
'
,
'
init() exception: %s
'
,
e
.
message
)
this
.
currentState
(
'
closing
'
)
this
.
quit
().
then
(
_
=>
{
this
.
currentState
(
'
close
'
)
})
await
this
.
quit
()
throw
e
}
...
...
@@ -266,17 +258,21 @@ class Browser extends EventEmitter {
public
async
restart
():
Promise
<
void
>
{
log
.
verbose
(
'
PuppetWebBrowser
'
,
'
restart()
'
)
await
this
.
quit
()
if
(
this
.
targetState
()
!==
'
open
'
&&
this
.
currentState
()
!==
'
opening
'
)
{
await
this
.
init
()
if
(
this
.
currentState
()
===
'
opening
'
)
{
log
.
warn
(
'
PuppetWebBrowser
'
,
'
restart() found currentState === opening
'
)
return
}
await
this
.
init
()
}
public
async
quit
():
Promise
<
any
>
{
log
.
verbose
(
'
PuppetWebBrowser
'
,
'
quit()
'
)
this
.
targetState
(
'
close
'
)
//
this.targetState('close')
this
.
currentState
(
'
closing
'
)
if
(
!
this
.
driver
)
{
...
...
@@ -539,8 +535,7 @@ class Browser extends EventEmitter {
if
(
dead
)
{
log
.
warn
(
'
PuppetWebBrowser
'
,
'
dead() because %s
'
,
msg
)
this
.
currentState
(
'
closing
'
)
this
.
restart
().
then
(
_
=>
this
.
currentState
(
'
close
'
))
this
.
quit
()
// must use nextTick here, or promise will hang... 2016/6/10
setImmediate
(
_
=>
{
...
...
src/puppet-web/event.ts
浏览文件 @
5e9c6715
...
...
@@ -49,60 +49,44 @@ const PuppetWebEvent = {
async
function
onBrowserDead
(
this
:
PuppetWeb
,
e
):
Promise
<
void
>
{
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead(%s)
'
,
e
&&
e
.
message
||
e
)
// because this function is async, so maybe entry more than one times.
// guard by variable: isBrowserBirthing to prevent the 2nd time entrance.
// if (this.isBrowserBirthing) {
// log.warn('PuppetWebEvent', 'onBrowserDead() is busy, this call will return now. stack: %s', (new Error()).stack)
// return
// }
if
(
this
.
browser
&&
this
.
browser
.
targetState
()
!==
'
open
'
)
{
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead() will do nothing because browser.targetState(%s) !== open
'
,
this
.
browser
.
targetState
())
return
if
(
!
this
.
browser
||
!
this
.
bridge
)
{
throw
new
Error
(
'
browser or bridge instance not exist in PuppetWeb instance
'
)
}
if
(
this
.
browser
&&
this
.
browser
.
currentState
()
===
'
opening
'
)
{
log
.
warn
(
'
PuppetWebEvent
'
,
'
onBrowserDead() will do nothing because browser.currentState = opening. stack: %s
'
,
(
new
Error
()).
stack
)
// because this function is async, so maybe entry more than one times.
// guard by variable: isBrowserBirthing to prevent the 2nd time entrance.
if
(
this
.
browser
.
targetState
()
!==
'
open
'
||
this
.
browser
.
currentState
()
===
'
opening
'
)
{
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead() will do nothing because browser.targetState(%s) !== open or browser.currentState = opening
'
,
this
.
browser
.
targetState
()
)
return
}
const
TIMEOUT
=
180000
// 180s / 3m
// this.watchDog(`onBrowserDead() set a timeout of ${Math.floor(TIMEOUT / 1000)} seconds to prevent unknown state change`, {timeout: TIMEOUT})
this
.
emit
(
'
watchdog
'
,
{
data
:
`onBrowserDead() set a timeout of
${
Math
.
floor
(
TIMEOUT
/
1000
)}
seconds to prevent unknown state change`
,
timeout
:
TIMEOUT
})
this
.
scan
=
null
// return co.call(this, function* () {
try
{
// log.verbose('PuppetWebEvent', 'onBrowserDead() co() set isBrowserBirthing true')
// this.isBrowserBirthing = true
const
TIMEOUT
=
180000
// 180s / 3m
// this.watchDog(`onBrowserDead() set a timeout of ${Math.floor(TIMEOUT / 1000)} seconds to prevent unknown state change`, {timeout: TIMEOUT})
this
.
emit
(
'
watchdog
'
,
{
data
:
`onBrowserDead() set a timeout of
${
Math
.
floor
(
TIMEOUT
/
1000
)}
seconds to prevent unknown state change`
,
timeout
:
TIMEOUT
})
if
(
!
this
.
browser
||
!
this
.
bridge
)
{
const
err
=
new
Error
(
'
no browser or no bridge
'
)
log
.
error
(
'
PuppetWebEvent
'
,
'
onBrowserDead() %s
'
,
err
.
message
)
throw
err
}
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead() try to reborn browser
'
)
await
this
.
browser
.
restart
()
.
catch
((
err
:
Error
)
=>
{
// fail safe
log
.
warn
(
'
PuppetWebEvent
'
,
'
browser.quit() exception: %s
'
,
err
.
stack
)
})
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead() old browser quited
'
)
await
this
.
browser
.
quit
()
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead() browser quit-ed
'
)
if
(
this
.
browser
.
targetState
()
!==
'
open
'
)
{
log
.
warn
(
'
PuppetWebEvent
'
,
'
onBrowserDead() will not init browser because browser.targetState(%s) !== open
'
,
this
.
browser
.
targetState
())
log
.
warn
(
'
PuppetWebEvent
'
,
'
onBrowserDead() will not init browser because browser.targetState(%s) !== open
'
,
this
.
browser
.
targetState
()
)
return
}
this
.
browser
=
await
this
.
initBrowser
()
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead() new browser inited
'
)
// this.bridge = await this.bridge.init()
this
.
bridge
=
await
this
.
initBridge
()
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead() bridge re-inited
'
)
...
...
@@ -110,27 +94,26 @@ async function onBrowserDead(this: PuppetWeb, e): Promise<void> {
if
(
/dong/i
.
test
(
dong
))
{
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead() ding() works well after reset
'
)
}
else
{
log
.
warn
(
'
PuppetWebEvent
'
,
'
onBrowserDead() ding() get error return after reset:
'
+
dong
)
const
e
=
new
Error
(
'
ding() got "
'
+
dong
+
'
", should be "dong"
'
)
log
.
warn
(
'
PuppetWebEvent
'
,
'
onBrowserDead() %s
'
,
e
.
message
)
throw
e
}
// }).catch(err => { // Exception
}
catch
(
e
)
{
log
.
error
(
'
PuppetWebEvent
'
,
'
onBrowserDead() exception: %s
'
,
e
.
message
)
log
.
warn
(
'
PuppetWebEvent
'
,
'
onBrowserDead() try to re-init PuppetWeb itself
'
)
return
this
.
quit
()
.
catch
(
error
=>
log
.
warn
(
'
PuppetWebEvent
'
,
'
onBrowserDead() fail safe for this.quit(): %s
'
,
error
.
message
))
.
then
(
_
=>
this
.
init
())
try
{
await
this
.
quit
()
await
this
.
init
()
}
catch
(
err
)
{
log
.
warn
(
'
PuppetWebEvent
'
,
'
onBrowserDead() fail safe for this.quit(): %s
'
,
err
.
message
)
}
}
// .then(() => { // Finally
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead() new browser borned
'
)
// this.isBrowserBirthing = false
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead() new browser borned
'
)
this
.
emit
(
'
watchdog
'
,
{
data
:
`onBrowserDead() new browser borned`
,
type
:
'
POISON
'
})
// })
this
.
emit
(
'
watchdog
'
,
{
data
:
`onBrowserDead() new browser borned`
,
type
:
'
POISON
'
})
return
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录