jxhczhl / JsRpc

远程调用(rpc)浏览器方法,免去抠代码补环境
1.16k stars 297 forks source link

注册的函数的返回结果是不是有限制 #16

Closed an-Underpriviliged-ZJUer closed 11 months ago

an-Underpriviliged-ZJUer commented 11 months ago

比如返回数组;似乎得到的总是字符串

an-Underpriviliged-ZJUer commented 11 months ago

我的python:

def send_rpc( group='test_group', name='test_name', funcName=None,param={}, b=None,**leak ): import requests import json url = "http://localhost:12080/go" data = { "group": group, "name": name, "action": "callFunctionByName", "param": json.dumps(merge({"funcName":funcName},param)) } return jsontodict(requests.post(url, data=data).text)['data']

an-Underpriviliged-ZJUer commented 11 months ago

更改后的Js_环境: handler.regAction("callFunctionByName", function (resolve, param) { funcName = param.funcName if (typeof funcName === 'string' && typeof functions[funcName] === 'function') { res = functionsfuncName resolve(res) } }) funciton{}中的两个函数:

e ({ xpath = null }) { const elements = this.es({ xpath }) if (elements.length === 0) { console.log(Element with XPath ${xpath} not found.) return null } return elements[0] }, es ({ xpath }) { let attr = null if (xpath.includes("//@")) { attr = xpath.split("//@")[1] xpath = xpath.split("//@")[0] } else if (xpath.includes("/@")) { attr = xpath.split("/@")[1] xpath = xpath.split("/@")[0] } else if (xpath.includes("/text()")) { attr = "text" xpath = xpath.split("/text()")[0] } const snapshot = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null) const nodes = [] for (let i = 0; i < snapshot.snapshotLength; i++) { const node = snapshot.snapshotItem(i) if (attr) { if (attr === "text") { nodes.push(node.textContent) } else { nodes.push(node.getAttribute(attr)) } } else { nodes.push(node) } } console.log(查询元素 ${xpath} 成功,共有 ${nodes.length} 个) return nodes }, 这种时候就不能返回原本是数组形式的nodes

an-Underpriviliged-ZJUer commented 11 months ago

改好了。唉浪费我时间去学js Hlclient.prototype.sendResult = function (action, e) { const jsonData = JSON.stringify(e); this.send(action + atob("aGxeX14") + jsonData); }