无法检查是否已打开“已安装扩展程序”页面

时间:2019-07-03 15:38:51

标签: puppeteer

我有一个扩展程序,该扩展程序具有 chrome.runtime.onInstalled 事件的侦听器,该扩展程序在安装扩展程序时会打开一个新页面。我可以使用以下配置在普通的Chrome和puppeteer中看到这种情况:

  browser = await puppeteer.launch({
    headless: false,
    args: [
      `--disable-extensions-except=${extensionPath}`,
      `--load-extension=${extensionPath}`
    ]
  })
  page = await browser.newPage()
  await page.setViewport({
    width: config.viewport.width,
    height: config.viewport.height
  })

但是我似乎无法获得此新标签的数据,该数据应通过以下命令返回:

    let pages = await browser.targets()
    pages.forEach( (v, i) => {
      console.log(i, v._targetInfo)
    })

仅返回以下内容:

  console.log test/installedExtension.test.js:49
    0 { targetId: '2E60BA3854355C415D48D89AA65727BC',
      type: 'page',
      title: '',
      url: 'about:blank',
      attached: false,
      browserContextId: '11F90429E632C8BC5C0073B1B74D0497' }

  console.log test/installedExtension.test.js:49
    1 { targetId: '416b3c97-04e7-4042-9401-d5ea7880bf22',
      type: 'browser',
      title: '',
      url: '',
      attached: true }

  console.log test/installedExtension.test.js:49
    2 { targetId: 'A8AA1B73923E934D284BD65CBF779956',
      type: 'background_page',
      title: 'Some Random Title',
      url:
       'chrome-extension://kmendfapggjehodndflmmgagdbamhnfd/_generated_background_page.html',
      attached: false,
      browserContextId: '11F90429E632C8BC5C0073B1B74D0497' }

  console.log test/installedExtension.test.js:49
    3 { targetId: '0A42832C4BD6539557765E8E99F113ED',
      type: 'background_page',
      title: 'My Extension Title',
      url:
       'chrome-extension://kpepplbhmfgaiibhacpojdokimblkbnh/src/background.html',
      attached: false,
      browserContextId: '11F90429E632C8BC5C0073B1B74D0497' }

  console.log test/installedExtension.test.js:49
    4 { targetId: 'C5B3440C60F001E559B01F364093F6CF',
      type: 'page',
      title: '',
      url: 'about:blank',
      attached: true,
      browserContextId: '11F90429E632C8BC5C0073B1B74D0497' }

尽管它带给我有关扩展程序背景HTML的信息,但我需要获取打开的标签,以进行一些断言。

有人对此事有想法吗?

0 个答案:

没有答案