XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Support undefined result

622215b4
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +3 -3
Modified g4f/requests/cdp.py +3 -3
@@ -1035,7 +1035,7 @@ class CDPSession:
1035 1035 res = await self.call(
1036 1036 "Runtime.evaluate", expression=expression, returnByValue=True
1037 1037 )
1038 if "result" not in res or "value" not in res["result"]:
1038 if "result" not in res or "value" not in res["result"] and res["result"].get("type") != "undefined":
1039 1039 raise RuntimeError(f"JavaScript evaluation failed: {res}")
1040 1040 return res.get("result", {}).get("value")
1041 1041
@@ -1078,13 +1078,13 @@ class CDPSession:
1078 1078 """Navigate to a URL and wait for it to load."""
1079 1079
1080 1080 await self.call("Page.navigate", url=url)
1081 await self.evaluate_js("new Promise(resolve => window.addEventListener('load', resolve))")
1081 await self.evaluate_js("(async () => await new Promise(resolve => window.addEventListener('load', resolve)))()")
1082 1082
1083 1083 async def reload(self):
1084 1084 """Reload the current page and wait for it to load."""
1085 1085
1086 1086 await self.call("Page.reload")
1087 await self.evaluate_js("new Promise(resolve => window.addEventListener('load', resolve))")
1087 await self.evaluate_js("(async () => await new Promise(resolve => window.addEventListener('load', resolve)))()")
1088 1088
1089 1089 async def wait_for_network_idle(
1090 1090 self, idle_time: float = 0.5, timeout: float = 15.0