babalae/better-genshin-impact · warning · ArgumentException
requestId cannot be empty
Error message
requestId cannot be empty
What it means
Thrown by HtmlMask.Respond when requestId is null, empty, or whitespace. The requestId is the correlation ID that ties a response back to a pending request from the HTML page (obtained from Receive/Poll/PollAll message objects). It must never be generated by the script itself.
Source
Thrown at BetterGenshinImpact/Core/Script/Dependence/HtmlMask.cs:207
queue.Enqueue(new Message
{
Url = url,
Data = ParseData(jsonData)
});
HtmlMaskWindow.NotifyFlush(windowId);
}
/// <summary>
/// 响应 HTML 页面通过 window.htmlMask.request(...) 发起的请求。
/// </summary>
/// <param name="windowId">HTML 遮罩窗口 ID。</param>
/// <param name="requestId">从 Receive/Poll/PollAll 返回消息的 requestId 字段取得,不能由脚本自行生成。</param>
/// <param name="jsonData">响应数据,必须是合法 JSON 字符串。</param>
public void Respond(string windowId, string requestId, string jsonData)
{
if (string.IsNullOrWhiteSpace(requestId))
throw new ArgumentException("requestId cannot be empty", nameof(requestId));
if (!HtmlMaskWindow.Exists(windowId) || !_toHtmlQueues.TryGetValue(windowId, out var queue))
throw new InvalidOperationException($"HTML遮罩窗口不存在或已关闭: {windowId}");
queue.Enqueue(new Message
{
Url = "/__response__",
Data = ParseData(jsonData),
RequestId = requestId
});
HtmlMaskWindow.NotifyFlush(windowId);
}
/// <summary>
/// 发送请求到HTML并等待响应
/// </summary>
/// <param name="windowId">目标窗口ID</param>View on GitHub (pinned to a7cb36712d)
Solutions
- Always extract requestId from the message object returned by Receive, Poll, or PollAll.
- Check string.IsNullOrWhiteSpace(requestId) before calling Respond and skip or log a warning.
- Only call Respond for messages that have a non-empty requestId (request-type messages, not push-type).
Example fix
// before
htmlMask.Respond(windowId, "", responseData);
// after
var msg = htmlMask.Receive(windowId, timeoutMs);
if (msg != null && !string.IsNullOrWhiteSpace(msg.requestId))
{
htmlMask.Respond(windowId, msg.requestId, responseData);
}
else
{
_logger.LogDebug("No pending request to respond to");
} Defensive patterns
Strategy: validation
Validate before calling
// Validate requestId before calling Respond
if (string.IsNullOrWhiteSpace(requestId))
{
_logger.LogDebug("Cannot respond: requestId is empty");
return;
}
htmlMask.Respond(windowId, requestId, jsonData); Prevention
- Always extract requestId from the message returned by Receive/Poll/PollAll.
- Never generate requestId yourself — it must come from the HTML page's request.
- Only call Respond for request-type messages that have a non-empty requestId.
When it happens
Trigger: Calling htmlMask.Respond(windowId, requestId, jsonData) where requestId is empty — typically because the script forgot to extract it from the received message, or passed a default/empty string.
Common situations: Script hardcodes requestId as "" instead of reading it from the message returned by Receive/Poll. The message object's requestId field was not populated (e.g., for a non-request message). Refactor changed the message field access path and left requestId null.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/830f90bb4539f3ef.
Report an issue: GitHub.