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


TypeScript puppeteer.Browser类代码示例

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


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

示例1: open

export async function open(name: string, browser: Browser, code: string, id: string = '#test'): Promise<Page> {
  const page = await browser.newPage()

  const content = `
  <!doctype html>
  <html>
    <head>
      <title>${name}</title>
    </head>
    <body>
      <div id="app"></div>
      <script>
      ${encode(await VUE_SOURCE)}
      </script>
      <script>
      ${encode(await code)}
      </script>
    </body>
  </html>`

  // Un-comment following lines to debug generated HTML.
  if (!Boolean(process.env.CI)) {
    const dir = path.join(__dirname, '../output')

    if (!await promised(fs).exists(dir)) await promised(fs).mkdir(dir)
    await promised(fs).writeFile(path.join(dir, name + '.html'), content)
  }

  await page.setContent(content)

  await page.waitFor(id)

  return page
}
开发者ID:liekkas,项目名称:rollup-plugin-vue,代码行数:34,代码来源:index.ts

示例2: init

  public async init(): Promise<void> {
    log.verbose('PuppetPuppeteerBridge', 'init()')

    this.state.on('pending')
    try {
      this.browser = await this.initBrowser()
      log.verbose('PuppetPuppeteerBridge', 'init() initBrowser() done')

      this.on('load', this.onLoad.bind(this))

      const ready = new Promise(resolve => this.once('ready', resolve))
      this.page = await this.initPage(this.browser)
      await ready

      this.state.on(true)
      log.verbose('PuppetPuppeteerBridge', 'init() initPage() done')
    } catch (e) {
      log.error('PuppetPuppeteerBridge', 'init() exception: %s', e)
      this.state.off(true)

      try {
        if (this.page) {
          await this.page.close()
        }
        if (this.browser) {
          await this.browser.close()
        }
      } catch (e2) {
        log.error('PuppetPuppeteerBridge', 'init() exception %s, close page/browser exception %s', e, e2)
      }

      this.emit('error', e)
      throw e
    }
  }
开发者ID:miggame,项目名称:wechaty,代码行数:35,代码来源:bridge.ts

示例3: 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

示例4: initBrowser

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

    const headless = this.options.head ? false : true
    const browser = await launch({
      headless,
      args: [
        '--audio-output-channels=0',
        '--disable-default-apps',
        '--disable-extensions',
        '--disable-translate',
        '--disable-gpu',
        '--disable-setuid-sandbox',
        '--disable-sync',
        '--hide-scrollbars',
        '--mute-audio',
        '--no-sandbox',
      ],
    })

    const version = await browser.version()
    log.verbose('PuppetPuppeteerBridge', 'initBrowser() version: %s', version)

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

示例5: async

beforeEach(async () => {
    page = await browser.newPage();
    page.on('dialog', async (dialog) => {
        await dialog.dismiss();
    });
    errors = errorWatcher(page);
});
开发者ID:rla,项目名称:feeds,代码行数:7,代码来源:app.test.ts

示例6: quit

  public async quit(): Promise<void> {
    log.verbose('PuppetPuppeteerBridge', 'quit()')

    if (!this.page) {
      throw new Error('no page')
    }
    if (!this.browser) {
      throw new Error('no browser')
    }

    this.state.off('pending')

    try {
      await this.page.close()
      log.silly('PuppetPuppeteerBridge', 'quit() page.close()-ed')
    } catch (e) {
      log.warn('PuppetPuppeteerBridge', 'quit() page.close() exception: %s', e)
    }

    try {
      await this.browser.close()
      log.silly('PuppetPuppeteerBridge', 'quit() browser.close()-ed')
    } catch (e) {
      log.warn('PuppetPuppeteerBridge', 'quit() browser.close() exception: %s', e)
    }

    this.state.off(true)
  }
开发者ID:miggame,项目名称:wechaty,代码行数:28,代码来源:bridge.ts

示例7:

afterAll(async () => {
    await browser.close();
    app.kill();
});
开发者ID:rla,项目名称:feeds,代码行数:4,代码来源:app.test.ts


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