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

Method subscribe

javascript/selenium-webdriver/bidi/index.js:295–331  ·  view source on GitHub ↗

* Subscribe to events. * * Not the correct implementation — this is not tied to a subscription id, so * unsubscribe below cancels by event/context name and can affect a * subscription made elsewhere (including via addCallback) for the * same event. Kept as-is only beca

(events, browsingContexts)

Source from the content-addressed store, hash-verified

293 * @returns {Promise<void>}
294 */
295 async subscribe(events, browsingContexts) {
296 function toArray(arg) {
297 if (arg === undefined) {
298 return []
299 }
300
301 return Array.isArray(arg) ? [...arg] : [arg]
302 }
303
304 const eventsArray = toArray(events)
305 const contextsArray = toArray(browsingContexts)
306
307 const params = {
308 method: 'session.subscribe',
309 params: {},
310 }
311
312 if (eventsArray.length && eventsArray.some((event) => typeof event !== 'string')) {
313 throw new TypeError('events should be string or string array')
314 }
315
316 if (contextsArray.length && contextsArray.some((context) => typeof context !== 'string')) {
317 throw new TypeError('browsingContexts should be string or string array')
318 }
319
320 if (eventsArray.length) {
321 params.params.events = eventsArray
322 }
323
324 if (contextsArray.length) {
325 params.params.contexts = contextsArray
326 }
327
328 this.events.push(...eventsArray)
329
330 await this.send(params)
331 }
332
333 /**
334 * Unsubscribe to events. See the note on {@link subscribe} above — this

Callers 6

initMethod · 0.45
_subscribe_to_eventFunction · 0.45

Calls 1

sendMethod · 0.95

Tested by

no test coverage detected