forked from fkasler/cuddlephish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresize_window.js
38 lines (37 loc) · 1.03 KB
/
resize_window.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
async function resize_window(browser, page, width, height) {
await page.setViewport({height, width})
// Window frame - probably OS and WM dependent.
//height += 85
height += 225
// Any tab.
const targets = await browser._connection.send(
'Target.getTargets'
)
// modified code
const target = targets.targetInfos.filter(t => t.attached === true && t.type === 'page')[0]
// Tab window.
const {windowId} = await browser._connection.send(
'Browser.getWindowForTarget',
{targetId: target.targetId}
)
const {bounds} = await browser._connection.send(
'Browser.getWindowBounds',
{windowId}
)
const resize = async () => {
await browser._connection.send('Browser.setWindowBounds', {
bounds: {width: width, height: height},
windowId
})
}
if(bounds.windowState === 'normal') {
await resize()
} else {
await browser._connection.send('Browser.setWindowBounds', {
bounds: {windowState: 'minimized'},
windowId
})
await resize()
}
}
export default resize_window