Repository navigation
feat: 浏览器 UA 设置、WebDAV 备份同步、待办增强与多项 Bug 修复 #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AiYuan4047
wants to merge
1
commit into
jieapi:main
Choose a base branch
from
AiYuan4047:feat/rc2-aiyuan
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
109 changes: 109 additions & 0 deletions
109
app/src/main/java/com/aicode/feature/agent/domain/tool/browser/BrowserUserAgent.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| package com.aicode.feature.agent.domain.tool.browser | ||
|
|
||
| /** | ||
| * 浏览器 User-Agent 预设。 | ||
| * | ||
| * 用户在「设置 → 运行环境 → 浏览器 → UA 设置」中选择,浏览器新建标签时套用对应的 | ||
| * User-Agent 字符串与客户端提示(client hints)平台信息。 | ||
| * | ||
| * [DEFAULT] 表示不覆盖,使用系统 WebView 的默认 UA;其余为常见设备/系统 UA。 | ||
| * [WINDOWS_10] 与 [WINDOWS_11] 的 UA 字符串一致(Windows 11 的 UA 仍报 Windows NT 10.0), | ||
| * 区别体现在客户端提示的 platform-version。 | ||
| */ | ||
| enum class BrowserUserAgent( | ||
| val id: String, | ||
| /** Android 手机 UA。 */ | ||
| val userAgent: String?, | ||
| /** 客户端提示 sec-ch-ua-platform(含引号按原样传入),null 表示不设置。 */ | ||
| val platform: String? = null, | ||
| val platformVersion: String? = null, | ||
| val architecture: String? = null, | ||
| val bitness: Int = 64, | ||
| val mobile: Boolean = false | ||
| ) { | ||
| /** 系统默认,不覆盖 UA。 */ | ||
| DEFAULT("default", null), | ||
|
|
||
| /** 安卓手机。 */ | ||
| ANDROID_PHONE( | ||
| id = "android_phone", | ||
| userAgent = "Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 " + | ||
| "(KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36", | ||
| platform = "Android", | ||
| platformVersion = "14.0.0", | ||
| mobile = true | ||
| ), | ||
|
|
||
| /** 安卓平板。 */ | ||
| ANDROID_TABLET( | ||
| id = "android_tablet", | ||
| userAgent = "Mozilla/5.0 (Linux; Android 14; Pixel Tablet) AppleWebKit/537.36 " + | ||
| "(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", | ||
| platform = "Android", | ||
| platformVersion = "14.0.0", | ||
| mobile = false | ||
| ), | ||
|
|
||
| /** Windows 10 电脑。 */ | ||
| WINDOWS_10( | ||
| id = "windows_10", | ||
| userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " + | ||
| "(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", | ||
| platform = "Windows", | ||
| platformVersion = "10.0.0", | ||
| architecture = "x86" | ||
| ), | ||
|
|
||
| /** Windows 11 电脑(UA 同 Win10,客户端提示版本不同)。 */ | ||
| WINDOWS_11( | ||
| id = "windows_11", | ||
| userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " + | ||
| "(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", | ||
| platform = "Windows", | ||
| platformVersion = "13.0.0", | ||
| architecture = "x86" | ||
| ), | ||
|
|
||
| /** Mac 电脑(Intel 芯片)。 */ | ||
| MAC_INTEL( | ||
| id = "mac_intel", | ||
| userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 " + | ||
| "(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", | ||
| platform = "macOS", | ||
| platformVersion = "15.0.0", | ||
| architecture = "x86" | ||
| ), | ||
|
|
||
| /** Mac 电脑(Apple 芯片)。 */ | ||
| MAC_APPLE_SILICON( | ||
| id = "mac_apple_silicon", | ||
| userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 " + | ||
| "(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", | ||
| platform = "macOS", | ||
| platformVersion = "15.0.0", | ||
| architecture = "arm" | ||
| ); | ||
|
|
||
| companion object { | ||
| fun fromId(id: String?): BrowserUserAgent = | ||
| entries.firstOrNull { it.id == id } ?: DEFAULT | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * 浏览器工具可被 AI 调用的全部 action(与 [com.aicode.feature.agent.domain.tool.browser.BrowserTool] 的 actionEnum 一致)。 | ||
| * | ||
| * 作为「AI 控制浏览器权限」开关的唯一事实源:设置页按此顺序逐项渲染开关, | ||
| * 权限默认全开;用户关闭某项后,BrowserTool 执行时直接拒绝该 action。 | ||
| */ | ||
| object BrowserActionCatalog { | ||
| /** action 名,顺序即设置页展示顺序。 */ | ||
| val ALL: List<String> = listOf( | ||
| "navigate", "evaluate", | ||
| "click", "fill", "select", "hover", "press", | ||
| "getText", "getHtml", "getBackbone", "screenshot", "console", "wait", | ||
| "scroll", "dialog", | ||
| "back", "forward", "reload", | ||
| "newTab", "closeTab", "selectTab", "listTabs" | ||
| ) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: jieapi/AiCode
Length of output: 45494
🏁 Script executed:
Repository: jieapi/AiCode
Length of output: 17628
🌐 Web query:
site:developer.android.com/reference/androidx/webkit/WebViewCompat addDocumentStartJavaScript DOCUMENT_START_SCRIPT WebKit 1.12.1 supported feature💡 Result:
🏁 Script executed:
Repository: jieapi/AiCode
Length of output: 12276
🌐 Web query:
site:developer.android.com/reference/androidx/webkit/WebViewCompat#addDocumentStartJavaScript(android.webkit.WebView,java.lang.String,java.util.Set) runs before page JavaScript ScriptHandler remove allowed origin rules DOCUMENT_START_SCRIPT💡 Result:
🏁 Script executed:
Repository: jieapi/AiCode
Length of output: 13253
🌐 Web query:
site:developer.android.com/reference/android/webkit/WebView evaluateJavascript asynchronous currently displayed page WebViewClient onPageStarted page started loading callback ordering JavaScript execution💡 Result:
Register the mask at document start.
onPageStartedonly signals that the main-frame load began.evaluateJavascriptruns asynchronously in the currently displayed page, so it does not guarantee that the new document receives the mask before its scripts run. An early script can read unmasked navigator fields under a non-default preset.When
DOCUMENT_START_SCRIPTis supported, registerAUTOMATION_MASK_JSwithWebViewCompat.addDocumentStartJavaScriptbefore navigation and keep the registration in sync withsetUserAgent. Use the existingonPageStartedinjection only as a best-effort fallback when the feature is unavailable; it cannot provide the same ordering guarantee.🤖 Prompt for AI Agents