Skip to content

Commit 1f5dc04

Browse files
committed
Merge branch '227-headless-chrome-example' of https://github.com/paazmaya/HTML_CodeSniffer into paazmaya-227-headless-chrome-example
2 parents 0be3ec3 + e6688d4 commit 1f5dc04

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

README.markdown

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,43 @@ recent (or slightly less than recent) versions of Safari.
8080

8181
See the <code>Contrib/PhantomJS/HTMLCS_Run.js</code> file for more information.
8282

83+
#### Headless Google Chrome via Puppeteer
84+
85+
[Puppeteer](https://developers.google.com/web/tools/puppeteer/get-started) offers an
86+
easy way to interact with the page via Google Chrome.
87+
88+
This example assumes that there is the latest version of Google Chrome installed,
89+
hence only the `puppeteer-core` will be needed:
90+
91+
```sh
92+
npm i puppeteer-core
93+
```
94+
95+
The test script assumes a recent version of Node.js to be available.
96+
97+
```javascript
98+
const puppeteer = require('puppeteer-core');
99+
100+
(async () => {
101+
const browser = await puppeteer.launch({
102+
executablePath: 'Google Chrome binary location'
103+
});
104+
const page = await browser.newPage();
105+
page.on('console', msg => console.log(msg.text()));
106+
107+
await page.goto('web site URL');
108+
109+
await page.addScriptTag({
110+
path: 'build/HTMLCS.js'
111+
});
112+
await page.evaluate(function () {
113+
HTMLCS_RUNNER.run('WCAG2AA');
114+
});
115+
116+
await browser.close();
117+
})();
118+
```
119+
83120
#### Node & JSDom
84121

85122
HTML_CodeSniffer requires a dom to run, however, it is possible to run it entirely

0 commit comments

Comments
 (0)