# working-with-chrome-extensions
# Working with Chrome Extensions
Puppeteer 可以用来测试 Chrome 扩展
> **注意** Chrome / Chromium 扩展当前只能在非无头模式下使用。
下面的代码用来处理扩展的 [background page](https://developer.chrome.com/extensions/background_pages),该扩展的代码在 `./my-extension`:
```
const puppeteer = require('puppeteer');(async () => { const pathToExtension = require('path').join(__dirname, 'my-extension'); const browser = puppeteer.launch({ headless: false, args: [ `--disable-extensions-except=${pathToExtension}`, `--load-extension=${pathToExtension}` ] }); const targets = await browser.targets(); const backgroundPageTarget = targets.find(target => target.type() === 'background_page'); const backgroundPage = await backgroundPageTarget.page(); // 像处理任何其他页面一样测试背景页面。 await browser.close();})();
```
> **注意** 目前还无法测试扩展弹出窗口或内容脚本。
>
> puppeteer.js中文网|working-with-chrome-extensions
>
> puppeteer.js中文文档, puppeteer chrome, puppeteer firefox, puppeteer api 中文文档
>
> puppeteer.js中文网包含了Puppeteer中文文档,最新资讯,应用案例等。Puppeteer 是一个 Node 库,它提供了一个高级 API 来通过 DevTools 协议控制 Chromium 或 Chrome。
- Introduction
- 版本记录
- 概要
- puppeteer-vs-puppeteer-core
- 环境变量
- error-handling
- working-with-chrome-extensions
- class:puppeteer
- class:browserfetcher
- class:browser
- class:page
- class:worker
- class:accessibility
- class:keyboard
- class:mouse
- class:touchscreen
- class:tracing
- class:dialog
- class:consolemessage
- class:frame
- class:executioncontext
- class:jshandle
- class:elementhandle
- class:request
- class:response
- class:securitydetails
- class:target
- class:cdpsession
- class:coverage
- class:timeouterror