木偶:不确定的目标加载

时间:2018-07-16 04:50:58

标签: javascript node.js google-chrome-extension chromium puppeteer

我正在尝试加载在Puppeteer中工作的CRX,但永远无法始终加载它。几乎每次运行都会得出不同的结果:

browser = await puppeteer.launch({
  headless: false,
  args: [
    `--disable-extensions-except=${extPath}`,
    `--load-extension=${extPath}`
  ]
});

const targets = await browser.targets();

targets.forEach(x => {
  console.log(x._targetInfo.title, x._targetInfo.type);
});

一些跑步表演(以不同的顺序显示):

'CryptoTokenExtension' 'background_page'
'' 'page'
'' 'browser'

其他跑步节目:

'CryptoTokenExtension' 'background_page'
'' 'browser'
'' 'page'
'myext' 'background_page'

我在做什么错了?

更新:添加一个短暂的延迟似乎可行。也许应该将其内置到api中/也许已经存在,但我没有看到它?

browser = await puppeteer.launch({
  headless: false,
  args: [
    `--disable-extensions-except=${extPath}`,
    `--load-extension=${extPath}`
  ]
});

// poll instead of hope this is enough time?
const EXT_LOAD_DELAY = 100;
await sleep(EXT_LOAD_DELAY);

const targets = await browser.targets();

targets.forEach(x => {
  console.log(x._targetInfo.title, x._targetInfo.type);
});

0 个答案:

没有答案