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

Method evaluate

resources/zbrowser/client.js:102–111  ·  view source on GitHub ↗

* 在目标页面中执行 JS 函数 * * 函数会被序列化为字符串,在目标页面上下文中执行。 * 支持异步函数(返回 Promise),结果会自动 unwrap。 * * @param {Function} fn - 要执行的函数 * @param {...*} args - 传递给函数的参数(必须是可 JSON 序列化的) * @returns {ZBrowserClient} this * * 示例: * .evaluate(() => document.title) * .evaluate((selector) =>

(fn, ...args)

Source from the content-addressed store, hash-verified

100 * .evaluate((selector) => document.querySelector(selector)?.textContent, '.title')
101 */
102 evaluate(fn, ...args) {
103 if (typeof fn !== 'function') {
104 throw new Error('evaluate: first argument should be a function')
105 }
106 this._queue.push({
107 method: 'javascript',
108 args: [jsCodeTemplate(fn, args)]
109 })
110 return this
111 }
112
113 /**
114 * 等待操作

Callers 6

mouseMethod · 0.95
hoverMethod · 0.95
valueMethod · 0.95
checkMethod · 0.95
focusMethod · 0.95
scrollMethod · 0.95

Calls 1

jsCodeTemplateFunction · 0.85

Tested by

no test coverage detected