Skip to content

Commit d2d871c

Browse files
committed
Merge branch 'paazmaya-227-headless-chrome-example'
2 parents 0be3ec3 + 7c64bbd commit d2d871c

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

README.markdown

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,54 @@ 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+
// Replace with the path to the chrome executable in your file system. This one assumes MacOSX.
101+
const executablePath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
102+
103+
// Replace with the url you wish to test.
104+
const url = 'https://www.squiz.net';
105+
106+
(async () => {
107+
const browser = await puppeteer.launch({
108+
executablePath
109+
});
110+
111+
const page = await browser.newPage();
112+
113+
page.on('console', msg => {
114+
console.log(msg.text())
115+
});
116+
117+
await page.goto(url);
118+
119+
await page.addScriptTag({
120+
path: 'build/HTMLCS.js'
121+
});
122+
123+
await page.evaluate(function () {
124+
HTMLCS_RUNNER.run('WCAG2AA');
125+
});
126+
127+
await browser.close();
128+
})();
129+
```
130+
83131
#### Node & JSDom
84132

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

0 commit comments

Comments
 (0)