提交 c27b13c5 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

track #870

上级 fd8b64e9
...@@ -66,12 +66,15 @@ export class Bridge extends EventEmitter { ...@@ -66,12 +66,15 @@ export class Bridge extends EventEmitter {
try { try {
this.browser = await this.initBrowser() this.browser = await this.initBrowser()
log.info('PuppetWebBridge', 'init() initBrowser() down')
this.page = await this.initPage(this.browser) this.page = await this.initPage(this.browser)
log.info('PuppetWebBridge', 'init() initPage() down')
await this.readyAngular(this.page) await this.readyAngular(this.page)
await this.inject(this.page) await this.inject(this.page)
} catch (e) { } catch (e) {
log.silly('PuppetWebBridge', 'init() exception: %s', e && e.message || e) log.error('PuppetWebBridge', 'init() exception: %s', e)
throw e throw e
} }
} }
...@@ -101,8 +104,11 @@ export class Bridge extends EventEmitter { ...@@ -101,8 +104,11 @@ export class Bridge extends EventEmitter {
const page = await browser.newPage() const page = await browser.newPage()
const cookieList = this.options.profile.get('cookies') as Cookie[] const cookieList = this.options.profile.get('cookies') as Cookie[]
const domain = this.cookieDomain(cookieList) const url = this.entryUrl(cookieList)
await page.goto(domain) // Does this related to(?) the CI Error: exception: Navigation Timeout Exceeded: 30000ms exceeded
log.info('PuppetWebBridge', 'initPage() before page.goto(domain)')
await page.goto(url) // Does this related to(?) the CI Error: exception: Navigation Timeout Exceeded: 30000ms exceeded
log.info('PuppetWebBridge', 'initPage() after page.goto(domain)')
// , { // , {
// waitUntil: 'load', // https://github.com/GoogleChrome/puppeteer/issues/805 // waitUntil: 'load', // https://github.com/GoogleChrome/puppeteer/issues/805
...@@ -664,48 +670,52 @@ export class Bridge extends EventEmitter { ...@@ -664,48 +670,52 @@ export class Bridge extends EventEmitter {
/** /**
* name * name
*/ */
public cookieDomain(cookieList?: Cookie[]): string { public entryUrl(cookieList?: Cookie[]): string {
log.verbose('PuppetWebBridge', 'cookieDomain(%s)', cookieList) log.verbose('PuppetWebBridge', 'cookieDomain(%s)', cookieList)
const DEFAULT_HOSTNAME = 'https://wx.qq.com' const DEFAULT_URL = 'https://wx.qq.com'
if (!cookieList || cookieList.length === 0) { if (!cookieList || cookieList.length === 0) {
log.silly('PuppetWebBridge', 'cookieDomain() no cookie, return default %s', DEFAULT_HOSTNAME) log.silly('PuppetWebBridge', 'cookieDomain() no cookie, return default %s', DEFAULT_URL)
return DEFAULT_HOSTNAME return DEFAULT_URL
} }
const wxCookieList = cookieList.filter(c => /^webwx_auth_ticket|webwxuvid$/.test(c.name)) const wxCookieList = cookieList.filter(c => /^webwx_auth_ticket|webwxuvid$/.test(c.name))
if (!wxCookieList.length) { if (!wxCookieList.length) {
log.silly('PuppetWebBridge', 'cookieDomain() no valid cookie, return default hostname') log.silly('PuppetWebBridge', 'cookieDomain() no valid cookie, return default hostname')
return DEFAULT_HOSTNAME return DEFAULT_URL
} }
let domain = wxCookieList[0].domain let domain = wxCookieList[0].domain
if (!domain) { if (!domain) {
log.silly('PuppetWebBridge', 'cookieDomain() no valid domain in cookies, return default hostname') log.silly('PuppetWebBridge', 'cookieDomain() no valid domain in cookies, return default hostname')
return DEFAULT_HOSTNAME return DEFAULT_URL
} }
domain = domain.slice(1) domain = domain.slice(1)
if (domain === 'wechat.com') { if (domain === 'wechat.com') {
domain = 'web.wechat.com' domain = 'web.wechat.com'
} }
if (!/^http/.test(domain)) { let url
if (/^http/.test(url)) {
url = domain
} else {
// Protocol error (Page.navigate): Cannot navigate to invalid URL undefined // Protocol error (Page.navigate): Cannot navigate to invalid URL undefined
domain = 'https://' + domain url = `https://${domain}`
} }
log.silly('PuppetWebBridge', 'cookieDomain() got %s', domain) log.silly('PuppetWebBridge', 'cookieDomain() got %s', url)
return domain return url
} }
public async reload(): Promise<void> { public async reload(): Promise<void> {
log.verbose('PuppetWebBridge', 'reload()')
await this.page.reload() await this.page.reload()
return return
} }
public async evaluate(...args: any[]): Promise<string> { public async evaluate(...args: any[]): Promise<string> {
log.silly('PuppetWebBridge', 'evaluate()')
return await this.page.evaluate.apply(this.page, args) return await this.page.evaluate.apply(this.page, args)
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册