Skip to content

Commit

Permalink
docs(readme): syntax-highlight nested snippets in debugging section (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andersonaguiar committed May 5, 2020
1 parent 53d6fab commit 209e25c
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions README.md
Expand Up @@ -198,22 +198,28 @@ Puppeteer creates its own browser user profile which it **cleans up on every run
displaying. Instead of launching in headless mode, launch a full version of
the browser using `headless: false`:

const browser = await puppeteer.launch({headless: false});
```js
const browser = await puppeteer.launch({headless: false});
```

2. Slow it down - the `slowMo` option slows down Puppeteer operations by the
specified amount of milliseconds. It's another way to help see what's going on.

const browser = await puppeteer.launch({
headless: false,
slowMo: 250 // slow down by 250ms
});
```js
const browser = await puppeteer.launch({
headless: false,
slowMo: 250 // slow down by 250ms
});
```

3. Capture console output - You can listen for the `console` event.
This is also handy when debugging code in `page.evaluate()`:

page.on('console', msg => console.log('PAGE LOG:', msg.text()));
```js
page.on('console', msg => console.log('PAGE LOG:', msg.text()));

await page.evaluate(() => console.log(`url is ${location.href}`));
await page.evaluate(() => console.log(`url is ${location.href}`));
```

4. Use debugger in application code browser

Expand All @@ -223,7 +229,9 @@ Puppeteer creates its own browser user profile which it **cleans up on every run

- Use `{devtools: true}` when launching Puppeteer:

`const browser = await puppeteer.launch({devtools: true});`
```js
const browser = await puppeteer.launch({devtools: true});
```

- Change default test timeout:

Expand All @@ -235,7 +243,9 @@ Puppeteer creates its own browser user profile which it **cleans up on every run

- Add an evaluate statement with `debugger` inside / add `debugger` to an existing evaluate statement:

`await page.evaluate(() => {debugger;});`
```js
await page.evaluate(() => {debugger;});
```

The test will now stop executing in the above evaluate statement, and chromium will stop in debug mode.

Expand All @@ -248,10 +258,12 @@ Puppeteer creates its own browser user profile which it **cleans up on every run
you want to try something out, you have to add it to your test file.

- Add `debugger;` to your test, eg:
```

```js
debugger;
await page.click('a[target=_blank]');
```

- Set `headless` to `false`
- Run `node --inspect-brk`, eg `node --inspect-brk node_modules/.bin/jest tests`
- In Chrome open `chrome://inspect/#devices` and click `inspect`
Expand Down

0 comments on commit 209e25c

Please sign in to comment.