MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / generateEventMethod

Function generateEventMethod

javascript/selenium-webdriver/generate_bidi.mjs:970–987  ·  view source on GitHub ↗
(evt)

Source from the content-addressed store, hash-verified

968}
969
970function generateEventMethod(evt) {
971 const { onMethodName, methodStr, paramsTypeName } = evt
972 const cbType = paramsTypeName ? `(params: ${paramsTypeName}) => void` : `(params: unknown) => void`
973
974 const lines = []
975 lines.push(` async ${onMethodName}(callback: ${cbType}): Promise<void> {`)
976 lines.push(` await this.bidi.subscribe('${methodStr}')`)
977 // bidi/index.js emits BiDi events by method name through its single shared
978 // message dispatcher (which already handles JSON parsing and closed-state
979 // guards). Using bidi.on() here avoids attaching a new ws.on('message', ...)
980 // listener on every subscription call, preventing listener accumulation and
981 // MaxListeners warnings.
982 lines.push(` this.bidi.on('${methodStr}', (params: unknown) => {`)
983 lines.push(` callback(${paramsTypeName ? `params as ${paramsTypeName}` : 'params'})`)
984 lines.push(` })`)
985 lines.push(` }`)
986 return lines.join('\n')
987}
988
989// ============================================================
990// Entry point

Callers 1

generateClassFunction · 0.85

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected