Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial release #1

Merged
merged 15 commits into from
Nov 26, 2019
13 changes: 13 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": [
[
"@babel/env",
{
"targets": {
"node": 8
}
}
],
"@babel/typescript"
scurker marked this conversation as resolved.
Show resolved Hide resolved
]
}
51 changes: 51 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: 2

defaults: &defaults
docker:
- image: circleci/node:8-browsers
working_director: ~/puppeteer-devtools

npm_cache_key: &npm_cache_key
v1-node-modules-cache-{{ checksum "package-lock.json" }}

restore_node_modules_cache: &restore_node_modules_cache
restore_cache:
keys:
- *npm_cache_key
- v1-node-modules-cache-

jobs:
dependencies:
<<: *defaults
steps:
- checkout
- <<: *restore_node_modules_cache
- run: npm ci
- save_cache:
paths:
- node_modules
key: *npm_cache_key
test:
<<: *defaults
steps:
- checkout
- <<: *restore_node_modules_cache
- run: npm run coverage
lint:
<<: *defaults
steps:
- checkout
- <<: *restore_node_modules_cache
- run: npm run lint

workflows:
version: 2
build:
jobs:
- dependencies
- test:
requires:
- dependencies
- lint:
requires:
- dependencies
6 changes: 6 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Reviewer checks

**Required fields, to be filled out by PR reviewer(s)**

- [ ] Follows the commit message policy, appropriate for next version
- [ ] Code is reviewed for security
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
.nyc_output
coverage
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,56 @@
# puppeteer-devtools
Extended puppeteer methods for getting extension devtools contexts

Extended puppeteer methods for getting extension devtools contexts.

> This package relies on using internal puppeteer methods to return the Chrome devtools panel, along with extension panels. Since it is dependent on undocumented puppeteer apis, it could break in future versions of Chrome/puppeteer so use at your own risk.

## Install

`npm install --save-dev puppeteer-devtools`

## Usage

```js
const puppeteer = require('puppeteer')
const { getDevtoolsPanel } = require('puppeteer-devtools')
const path = require('path')

const extension = path.resolve('/path/to/extension')

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

const [page] = await browser.pages()
const panel = await getDevtoolsPanel(page, { panelName: 'panel.html' })
```

Note: `devtools` must be enabled, and `headless` mode must be turned off. Chrome [does not currently support extensions in headless mode](https://bugs.chromium.org/p/chromium/issues/detail?id=706008).

## Methods

### async getDevtools( page, options? )

Returns the underlying Chrome `devtools://` page as a <code>Promise<[Page](https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#class-page)></code>.

- **`page`** - <[`Page`](https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#class-page)> Puppeteer page object.
- **`options`** - <`object`>
- **`timeout`** - <`number | null`> Maximum time in milliseconds to wait for the devtools page to become available. Uses puppeteer's default timeout if not set.

### async getDevtoolsPanel( page, options? )

Returns the underlying Chrome `chrome-extension://` panel as a <code>Promise<[Frame](https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#class-frame)></code>.

- **`page`** - <[`Page`](https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#class-page)> Puppeteer page object.
- **`options`** - <`object`>
- **`panelName`** - <`string`> The file name of the extension panel to find. A devtools page with `chrome.devtools.panels.create('name', 'icon.png', 'panel.html', (panel) => { ... })` would have `panel.html` as its value.
- **`timeout`** - <`number | null`> Maximum time in milliseconds to wait for the chrome extension panel to become available. Uses puppeteer's default timeout if not set.

## License

UNLICENSED
5 changes: 5 additions & 0 deletions ava.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
compileEnhancements: false,
extensions: ['ts'],
require: ['ts-node/register']
}