Skip to content

Commit

Permalink
Introduce DEBUG module
Browse files Browse the repository at this point in the history
This patch re-introduces the DEBUG module to expose some of
the puppeteer's internals.

Currently, only the protocol message communication is exposed under
the 'puppeteer:protocol' namespace.
  • Loading branch information
aslushnikov committed Jul 17, 2017
1 parent 4581ada commit 0414dfa
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
14 changes: 13 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ are used to test `phantom_shim`.

To run puppeteer tests, use:
```
npm run test-puppeteer
npm run unit
```

To run phantom-shim against phantomjs tests, use:
Expand All @@ -53,3 +53,15 @@ To run both puppeteer and phantom_shim tests, use:
npm test
```

## DEBUG module
Puppeteer uses [debug](https://github.com/visionmedia/debug) module to expose some of it's inner guts under the `puppeteer` namespace.
Try putting the following script in the `script.js` and running it via `DEBUG=* node script.js`:

```js
const {Browser} = require('puppeteer');
const browser = new Browser();
browser.newPage().then(async page => {
await page.navigate('https://example.com');
browser.close();
});
```
3 changes: 3 additions & 0 deletions lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
let debug = require('debug')('puppeteer:protocol');

let EventEmitter = require('events');
let WebSocket = require('ws');
Expand Down Expand Up @@ -46,6 +47,7 @@ class Connection extends EventEmitter {
send(method, params = {}) {
let id = ++this._lastId;
let message = JSON.stringify({id, method, params});
debug('◀ SEND ' + message);
this._ws.send(message);
return new Promise((resolve, reject) => {
this._callbacks.set(id, {resolve, reject, method});
Expand All @@ -56,6 +58,7 @@ class Connection extends EventEmitter {
* @param {string} message
*/
_onMessage(message) {
debug('RECV ► ' + message);
let object = JSON.parse(message);
if (object.id && this._callbacks.has(object.id)) {
let callback = this._callbacks.get(object.id);
Expand Down
29 changes: 22 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"author": "The Chromium Authors",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"debug": "^2.6.8",
"extract-zip": "^1.6.5",
"mime": "^1.3.4",
"progress": "^2.0.0",
Expand Down

0 comments on commit 0414dfa

Please sign in to comment.