MCPcopy
hub / github.com/ZToolsCenter/ZTools / wait

Method wait

resources/zbrowser/client.js:125–178  ·  view source on GitHub ↗

* 等待操作 * * 支持三种调用方式: * 1. wait(ms) - 等待指定毫秒数 * 2. wait(selector, options?) - 等待 DOM 元素出现 * - options: number(超时毫秒) 或 { timeout, interval } * 3. wait(fn, options?, ...args) - 等待函数返回 true * - 函数在目标页面上下文中执行 * * @returns {ZBrowserClient} this

(...args)

Source from the content-addressed store, hash-verified

123 * @returns {ZBrowserClient} this
124 */
125 wait(...args) {
126 // wait(ms)
127 if (typeof args[0] === 'number') {
128 this._queue.push({ method: 'wait', args: [args[0]] })
129 return this
130 }
131
132 // wait(selector, options?)
133 if (typeof args[0] === 'string') {
134 const optArg = args[1]
135 let timeout, interval
136 if (typeof optArg === 'object') {
137 timeout = optArg.timeout
138 interval = optArg.interval
139 } else if (typeof optArg === 'number') {
140 timeout = optArg
141 }
142 if (typeof timeout !== 'number' || timeout < 0) timeout = 60000
143 if (typeof interval !== 'number' || interval < 0) interval = 1000
144
145 this._queue.push({
146 method: 'wait',
147 args: [
148 jsCodeTemplate((selector) => !!document.querySelector(selector), [args[0]]),
149 timeout,
150 interval
151 ]
152 })
153 return this
154 }
155
156 // wait(fn, options?, ...fnArgs)
157 if (typeof args[0] === 'function') {
158 const fn = args.shift()
159 const optArg = args.shift()
160 let timeout, interval
161 if (typeof optArg === 'object') {
162 timeout = optArg.timeout
163 interval = optArg.interval
164 } else if (typeof optArg === 'number') {
165 timeout = optArg
166 }
167 if (typeof timeout !== 'number' || timeout < 0) timeout = 60000
168 if (typeof interval !== 'number' || interval < 0) interval = 1000
169
170 this._queue.push({
171 method: 'wait',
172 args: [jsCodeTemplate(fn, args), timeout, interval]
173 })
174 return this
175 }
176
177 throw new Error('wait: parameter error')
178 }
179
180 /**
181 * 条件分支

Callers

nothing calls this directly

Calls 1

jsCodeTemplateFunction · 0.85

Tested by

no test coverage detected