Skip to content

Commit c7203a5

Browse files
committed
implement BiDi command getClientWindows
1 parent 0721800 commit c7203a5

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

javascript/node/selenium-webdriver/bidi/browser.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
const { WindowState, ClientWindowInfo } = require('./clientWindowInfo')
19+
1820
/**
1921
* Represents the commands and events under Browser Module.
2022
* Described in https://w3c.github.io/webdriver-bidi/#module-browser
@@ -83,6 +85,20 @@ class Browser {
8385

8486
await this.bidi.send(command)
8587
}
88+
89+
/**
90+
* Gets information about all client windows.
91+
* @returns {Promise<ClientWindowInfo[]>} Array of client window information
92+
*/
93+
async getClientWindows() {
94+
const command = {
95+
method: 'browser.getClientWindows',
96+
params: {},
97+
}
98+
99+
const response = await this.bidi.send(command)
100+
return response.result.clientWindows.map((window) => ClientWindowInfo.fromJson(window))
101+
}
86102
}
87103

88104
async function getBrowserInstance(driver) {
@@ -92,3 +108,4 @@ async function getBrowserInstance(driver) {
92108
}
93109

94110
module.exports = getBrowserInstance
111+
module.exports.WindowState = WindowState
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
const WindowState = Object.freeze({
19+
FULLSCREEN: 'fullscreen',
20+
MAXIMIZED: 'maximized',
21+
MINIMIZED: 'minimized',
22+
NORMAL: 'normal',
23+
})
24+
25+
class ClientWindowInfo {
26+
/**
27+
* @param {Object} params Window information parameters
28+
* @param {string} params.clientWindow Window identifier
29+
* @param {string} params.state Window state from WindowState
30+
* @param {number} params.width Window width
31+
* @param {number} params.height Window height
32+
* @param {number} params.x Window x coordinate
33+
* @param {number} params.y Window y coordinate
34+
* @param {boolean} params.active Whether window is active and can receive keyboard input
35+
*/
36+
constructor({ clientWindow, state, width, height, x, y, active }) {
37+
this.clientWindow = clientWindow
38+
this.state = state
39+
this.width = width
40+
this.height = height
41+
this.x = x
42+
this.y = y
43+
this.active = active
44+
}
45+
46+
static fromJson(json) {
47+
return new ClientWindowInfo({
48+
...json,
49+
state: json.state.toLowerCase(),
50+
})
51+
}
52+
}
53+
54+
module.exports = { WindowState, ClientWindowInfo }

0 commit comments

Comments
 (0)