MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / Browser

Class Browser

javascript/selenium-webdriver/bidi/browser.js:24–102  ·  view source on GitHub ↗

* Represents the commands and events under Browser Module. * Described in https://w3c.github.io/webdriver-bidi/#module-browser

Source from the content-addressed store, hash-verified

22 * Described in https://w3c.github.io/webdriver-bidi/#module-browser
23 */
24class Browser {
25 constructor(driver) {
26 this._driver = driver
27 }
28
29 async init() {
30 if (!(await this._driver.getCapabilities()).get('webSocketUrl')) {
31 throw Error('WebDriver instance must support BiDi protocol')
32 }
33
34 this.bidi = await this._driver.getBidi()
35 }
36
37 /**
38 * Creates a new user context.
39 * @returns {Promise<string>} A promise that resolves to the user context id.
40 */
41 async createUserContext() {
42 const command = {
43 method: 'browser.createUserContext',
44 params: {},
45 }
46
47 let response = await this.bidi.send(command)
48
49 return response.result.userContext
50 }
51
52 /**
53 * Gets the list of all user contexts.
54 * @returns {Promise<string[]>} A promise that resolves to an array of user context ids.
55 */
56 async getUserContexts() {
57 const command = {
58 method: 'browser.getUserContexts',
59 params: {},
60 }
61
62 let response = await this.bidi.send(command)
63
64 let userContexts = []
65
66 let userContextsArray = response.result.userContexts
67
68 for (let userContextJson of userContextsArray) {
69 userContexts.push(userContextJson.userContext)
70 }
71
72 return userContexts
73 }
74
75 /**
76 * Removes a user context.
77 * @param {string} userContext The user context id to be removed.
78 * @returns {Promise<void>}
79 */
80 async removeUserContext(userContext) {
81 const command = {

Callers 1

browserMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected