如何从Puppeteer调用chrome.runtime.sendMessage?

时间:2019-06-18 09:08:19

标签: google-chrome-extension puppeteer

嗨,我正在尝试通过使用puppeteer中的chrome.runtime.sendMessage调用一个函数来使用puppeteer来测试扩展。

可悲的是,它一直返回TypeError: Cannot read property 'connect' of undefined,这使我相信在伪造者上下文中'chrome'不可用。

有人知道我该怎么做吗?

这是我到目前为止提出的:

const puppeteer = require('puppeteer');

async function boot() {
    let browser = await puppeteer.launch({
        executablePath: 'C:\\Program Files\\Google\\Chromium\\chrome',
        headless: false, // extension are allowed only in head-full mode
        args: [
            `--disable-extensions-except=C:\\dev\\my_extn\\src`,
            `--load-extension=C:\\dev\\my_extn\\src`
          ]
    });

    const deploymentPage = await browser.newPage();
    await deploymentPage.goto(`https://google.com`);

    chrome.runtime.sendMessage("myextensionId", { test: 'message' });
};

boot();

0 个答案:

没有答案