You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何不使用await改写fetch调用代码?解决eval中await失效问题

Hey there! Let's sort out this fetch/await issue you're hitting in AutoHotkey.

The problem with using await directly inside eval() is that eval runs in a non-async context—await only works inside an async function, which is why it wasn't taking effect. Since you mentioned you'll be checking window.items_list periodically anyway, we can rewrite the code to use plain Promise chaining instead of await, which works perfectly without needing an async wrapper.

Here's the revised code:

fetch(ff_url, ff_params)
  .then(response => response.json())
  .then(data => window.items_list = data.items);

This does exactly the same thing as your original code: it sends the request via fetch, parses the response as JSON, then assigns the items property from the response to window.items_list. The only difference is we're using fetch's built-in Promise chain instead of await, so it'll run correctly when injected via eval() in your AutoHotkey setup.

Since you're already planning to check for window.items_list being defined later, this fits your workflow perfectly—once the fetch completes and the JSON is parsed, the variable will be set, and your periodic check will pick it up.

内容的提问来源于stack exchange,提问作者Redbraid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 06:37:43