当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Page.setCookie方法代码示例

本文整理汇总了TypeScript中puppeteer.Page.setCookie方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Page.setCookie方法的具体用法?TypeScript Page.setCookie怎么用?TypeScript Page.setCookie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在puppeteer.Page的用法示例。


在下文中一共展示了Page.setCookie方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: initPage

  public async initPage(browser: Browser): Promise<Page> {
    log.verbose('PuppetPuppeteerBridge', 'initPage()')

    // set this in time because the following callbacks
    // might be called before initPage() return.
    const page = this.page =  await browser.newPage()

    page.on('error',  e => this.emit('error', e))

    page.on('dialog', this.onDialog.bind(this))

    const cookieList = (await this.options.profile.get('cookies')) as Cookie[]
    const url        = this.entryUrl(cookieList)

    log.verbose('PuppetPuppeteerBridge', 'initPage() before page.goto(url)')
    await page.goto(url) // Does this related to(?) the CI Error: exception: Navigation Timeout Exceeded: 30000ms exceeded
    log.verbose('PuppetPuppeteerBridge', 'initPage() after page.goto(url)')

    if (cookieList && cookieList.length) {
      await page.setCookie(...cookieList)
      log.silly('PuppetPuppeteerBridge', 'initPage() page.setCookie() %s cookies set back', cookieList.length)
    }

    page.on('load', () => this.emit('load', page))
    await page.reload() // reload page to make effect of the new cookie.

    return page
  }
开发者ID:miggame,项目名称:wechaty,代码行数:28,代码来源:bridge.ts

示例2: cookies

  public async cookies(cookieList?: Cookie[]): Promise<void | Cookie[]> {
    if (!this.page) {
      throw new Error('no page')
    }

    if (cookieList) {
      try {
        await this.page.setCookie(...cookieList)
      } catch (e) {
        log.error('PuppetPuppeteerBridge', 'cookies(%s) reject: %s', cookieList, e)
        this.emit('error', e)
      }
      return
    } else {
      // FIXME: puppeteer typing bug
      cookieList = await this.page.cookies() as any as Cookie[]
      return cookieList
    }
  }
开发者ID:miggame,项目名称:wechaty,代码行数:19,代码来源:bridge.ts


注:本文中的puppeteer.Page.setCookie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。