Skip to main content
Version: 22.6.1

Chrome 扩展程序

¥Chrome Extensions

Puppeteer 可用于测试 Chrome 扩展。

¥Puppeteer can be used for testing Chrome Extensions.


Chrome/Chromium 中的扩展程序目前仅在非无头模式和实验性 Chrome 无头模式下工作。

¥Extensions in Chrome/Chromium currently only work in non-headless mode and experimental Chrome headless mode.

以下是获取源位于 ./my-extension 的扩展的 背景页 句柄的代码:

¥The following is code for getting a handle to the background page of an extension whose source is located in ./my-extension:

import puppeteer from 'puppeteer';
import path from 'path';

(async () => {
const pathToExtension = path.join(process.cwd(), 'my-extension');
const browser = await puppeteer.launch({
headless: 'new',
args: [
const backgroundPageTarget = await browser.waitForTarget(
target => target.type() === 'background_page'
const backgroundPage = await;
// Test the background page as you would any other page.
await browser.close();

Chrome Manifest V3 扩展具有 'service_worker' 类型的后台 ServiceWorker,而不是 'background_page' 类型的页面。

¥Chrome Manifest V3 extensions have a background ServiceWorker of type 'service_worker', instead of a page of type 'background_page'.



¥It is not yet possible to test extension popups or content scripts.