Skip to content

Commit

Permalink
Merge branch 'master' of github.com:zixia/wechaty
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Jun 14, 2016
2 parents cd3e7d2 + 8617938 commit 574341c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/puppet-web-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Bridge {
, 'utf8'
)
}
inject() {
inject(attempt) {
log.verbose('PuppetWebBridge', 'inject()')
return co.call(this, function* () {
const injectio = this.getInjectio()
Expand All @@ -131,7 +131,13 @@ class Bridge {
return r
})
.catch (e => {
log.error('PuppetWebBridge', 'inject() exception: %s', e.message)
log.warn('PuppetWebBridge', 'inject() exception: %s', e.message)
attempt = attempt || 0
if (attempt++ < 3) {
log.warn('PuppetWebBridge', 'inject(%d) retry after 1 second: %s', attempt, e.message)
setTimeout(() => this.inject(attempt), 1000)
return
}
throw e
})
}
Expand All @@ -148,19 +154,19 @@ class Bridge {
// see: http://blog.sqrtthree.com/2015/08/29/utf8-to-b64/
const argsDecoded = `JSON.parse(decodeURIComponent(window.atob('${argsEncoded}')))`

const wechatyScript = `return (typeof Wechaty !== 'undefined' && Wechaty.${wechatyFunc}.apply(undefined, ${argsDecoded}))`
const wechatyScript = `return Wechaty.${wechatyFunc}.apply(undefined, ${argsDecoded})`
log.silly('PuppetWebBridge', 'proxyWechaty(%s, ...args) %s', wechatyFunc, wechatyScript)
return this.execute(wechatyScript)
.catch(e => {
log.warn('PuppetWebBridge', 'proxyWechaty() exception: %s', e.message || e)
log.warn('PuppetWebBridge', 'proxyWechaty() exception: %s', e.message)
throw e
})
}

execute(script, ...args) {
return this.options.puppet.browser.execute(script, ...args)
.catch(e => {
log.warn('PuppetWebBridge', 'execute() exception: %s', e.message || e)
log.warn('PuppetWebBridge', 'execute() exception: %s', e.message)
throw e
})
}
Expand Down
3 changes: 2 additions & 1 deletion src/puppet-web-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ class Browser extends EventEmitter {

return this.driver.executeScript.apply(this.driver, arguments)
.catch(e => {
this.dead(e)
// this.dead(e)
log.warn('PuppetWebBrowser', 'execute() exception: %s', e.message)
throw e
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/puppet-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class PuppetWeb extends Puppet {
this.bridge.init()
.then(r => log.verbose('PuppetWeb', 'onServerDisconnect() bridge re-inited: %s', r))
.catch(e => log.error('PuppetWeb', 'onServerDisconnect() exception: [%s]', e))
}, 10000) // 10 seconds should be enough to wait
}, 1000) // 1 second instead of 10 seconds? try. (should be enough to wait)
return
}
}
Expand Down

0 comments on commit 574341c

Please sign in to comment.