-
Notifications
You must be signed in to change notification settings - Fork 1
/
dev-tools.js
46 lines (37 loc) · 1.27 KB
/
dev-tools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const puppeteer = require('puppeteer-core');
const debug = require('debug')('hermione-hide-scrollbars');
module.exports = class DevTools {
static async create({browserWSEndpoint}) {
const browser = await puppeteer.connect({
browserWSEndpoint,
defaultViewport: null
});
return new DevTools(browser);
}
constructor(browser) {
this._browser = browser;
}
async hideScrollbarsOnActivePages() {
const pages = await this._browser.pages();
await Promise.all(pages.map((p) => disableScrollBarsOnPage(p.target())));
}
setScrollbarsHiddenOnNewPage() {
this._browser.on('targetcreated', async (target) => {
try {
const page = await target.page();
if (!page) {
return;
}
debug('new page opened. Hiding scrollbars');
await disableScrollBarsOnPage(target);
} catch (err) {
console.error('Coulnd\'t connect to CDP session:', err);
}
});
}
};
async function disableScrollBarsOnPage(target) {
const client = await target.createCDPSession();
await client.send('Emulation.setScrollbarsHidden', {hidden: true});
}