fix: normalize newlines when comparing synced prompt (CRLF breaks WAA proof) - #29
Merged
Merged
Conversation
Worker.Proof 把写入 textarea 的返回值与原始 prompt 直接按字节比较。 官网 textarea 会把写入值中的 CRLF 规范化为 LF,因此当客户端提示词 含 CRLF 时该比较永远不成立,5s 轮询后返回“官网 prompt 状态未同步”, GenerateContent 随之失败并向上游返回 502。 Windows 客户端很容易触发:多行请求体、工具结果或粘贴内容常带 CRLF。 本地实测(Pro 账户,gemini-3.8-flash): 修复前 LF 换行 200 16827ms 修复前 CRLF 换行 502 37449ms 修复后 LF 换行 200 2439ms 修复后 CRLF 换行 200 1558ms 新增 normalizePromptNewlines,仅在同步判定处归一化 CRLF/CR 为 LF。 写入页面的内容与 proof digest 仍使用原始 prompt,协议行为不变。 bootstrap 的 filled 比较存在同样问题,一并修复。 补充 page_test.go 覆盖归一化与 CRLF/LF 同步判定。 go vet、go test ./internal/camoufoxnative/、go build ./... 均通过。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Worker.Proof把写入 textarea 后读回的值与原始prompt直接按字节比较:官网 textarea 会把写入值中的 CRLF 规范化为 LF。所以当客户端提示词含 CRLF 时,
这个比较永远不成立,5s 轮询耗尽后返回
官网 prompt 状态未同步,GenerateContent 失败,上游收到 502。
Windows 客户端很容易触发:多行请求体、工具调用结果、粘贴内容通常带 CRLF。
单行短提示词可以通过,所以现象表现为“用一会儿就报错”。
bootstrap里的filled != options.BootstrapPrompt是同一个问题,目前默认 bootstrap 提示词不含换行所以没暴露,但同样需要修复。
修复
新增
normalizePromptNewlines,只在同步判定处把 CRLF/CR 归一化为 LF。写入页面的内容和 proof digest 仍使用原始
prompt,协议行为不变:fillPromptExpression(prompt)未改动,写入页面的仍是原始文本sha256.Sum256([]byte(request.Prompt))未改动,digest 仍基于原始文本验证
本地实测,Pro 账户,
gemini-3.8-flash,Windows 11:修复后用含 CRLF 的提示词跑完整协议面:
注意 LF 情况也从 16.8s 降到 2.4s。此前每个请求都在白等一轮 5s 轮询超时,
因为
evaluateString返回值与原文比较失败会重试到 deadline 附近才偶然通过。新增
internal/camoufoxnative/page_test.go,覆盖归一化本身和 CRLF/LF 同步判定。