MCPcopy
hub / github.com/SeleniumHQ/selenium / Script

Class Script

javascript/selenium-webdriver/lib/script.js:25–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23const by = require('./by')
24
25class Script {
26 #driver
27 #logInspector
28 #script
29
30 constructor(driver) {
31 this.#driver = driver
32 }
33
34 // This should be done in the constructor.
35 // But since it needs to call async methods we cannot do that in the constructor.
36 // We can have a separate async method that initialises the Script instance.
37 // However, that pattern does not allow chaining the methods as we would like the user to use it.
38 // Since it involves awaiting to get the instance and then another await to call the method.
39 // Using this allows the user to do this "await driver.script().addJavaScriptErrorHandler(callback)"
40 async #init() {
41 if (this.#logInspector !== undefined) {
42 return
43 }
44 this.#logInspector = await logInspector(this.#driver)
45 }
46
47 async #initScript() {
48 if (this.#script !== undefined) {
49 return
50 }
51 this.#script = await scriptManager([], this.#driver)
52 }
53
54 async addJavaScriptErrorHandler(callback) {
55 await this.#init()
56 return await this.#logInspector.onJavascriptException(callback)
57 }
58
59 async removeJavaScriptErrorHandler(id) {
60 await this.#init()
61 await this.#logInspector.removeCallback(id)
62 }
63
64 async addConsoleMessageHandler(callback) {
65 await this.#init()
66 return this.#logInspector.onConsoleEntry(callback)
67 }
68
69 async removeConsoleMessageHandler(id) {
70 await this.#init()
71
72 await this.#logInspector.removeCallback(id)
73 }
74
75 async addDomMutationHandler(callback) {
76 await this.#initScript()
77
78 let argumentValues = []
79 let value = LocalValue.createChannelValue(new ChannelValue('channel_name'))
80 argumentValues.push(value)
81
82 const filePath = path.join(__dirname, 'atoms', 'bidi-mutation-listener.js')

Calls

no outgoing calls