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

Add text highlight for Javascript on debugging section #5799

Merged
merged 2 commits into from May 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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