Repository navigation
fix(browser): publish the WebView devtools socket and resume the last page - #442
Merged
Merged
Conversation
…/proc/net/unix Android denies /proc/net/unix to untrusted_app, so the in-guest MCP server could never scan for webview_devtools_remote_<pid> and always reported 'not connected', even with agent control enabled. The app now publishes the socket name to .and-code/browser-devtools.txt (only after the agent-control opt-in) and the MCP server falls back to it, verifying with a connect probe.
yuga-hashimoto
force-pushed
the
fix/guest-browser-devtools-socket
branch
from
November 25, 2026 19:31
a21c79c to
9dda011
Compare
Contributor
|
Debug APK built successfully Download APK artifact Commit: |
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.
Problem
browser_status/browser_navigatefail with "WebView devtools socket not found" even thoughbrowser_showopens the browser. The MCP server discovers the socket by scanning/proc/net/unix, which SELinux denies tountrusted_app(Permission deniedinside the guest), so the scan can never succeed.With a socket found, every CDP tool still timed out: the WebView's
GET /jsonreplies withContent-Lengthand keeps the connection open, whilelist_targets()read until the text ended with]— which never happens — so it blocked until the socket timeout.Reopening the full-screen guest browser from Settings also started from a blank address bar every time, even after the user had been reading a page.
Fix
webview_devtools_remote_<pid>to.and-code/browser-devtools.txtin the active workspace, only when the agent-control opt-in is on./proc/net/unix, verifying with a connect probe so a closed socket still reports not connected.list_targets()now reads the HTTP body byContent-Length/ chunked encoding instead of waiting for the socket to close, sobrowser_status,browser_info,browser_click,browser_screenshotand the rest stop timing out.http(s)page in its own preferences and resumes it when opened without an explicit URL (agentbrowser_show/ preview handoff still win). Non-web pages are ignored, so a blank/error page never replaces the remembered one. Sign-in cookies stay in the WebView profile and are untouched.On-device check (module level, against a live WebView)
list_targets()returned the page target in 0.0 s after the fix (previously it blocked until the 10 s socket timeout).tool_inforeturned the URL/title,tool_screenshotproduced a valid PNG, andtool_clickclicked example.com's link and navigated to iana.org.Test plan
browser_showthenbrowser_statusreports connected (not a timeout)Pre-PR review
判定: APPROVE
ブロッカー
なし
提案(非ブロッキング)
origin/main(5a90380d)にはまだ fix(browser): publish the WebView devtools socket and resume the last page #442 の devtools 公開(publishDevtoolsSocketName/andcode-browser-mcp.pyの_published_devtools_socket)が入っていません。このブランチを main 向けに出すと fix(browser): publish the WebView devtools socket and resume the last page #442 の差分も含まれるため、fix(browser): publish the WebView devtools socket and resume the last page #442 を先にマージするか base を fix(browser): publish the WebView devtools socket and resume the last page #442 ブランチへ切り替える前提かを確認してください。GuestBrowserLastUrlはアプリ全体で1つの URL を保存するため、別ワークスペース/ランタイムで URL なしに開くと、前のhttp://127.0.0.1:<port>をそのまま復元して別サーバや到達不能ページを表示し得ます(GuestBrowserLastUrl.kt:18-27,GuestBrowserScreen.kt:55)。キーを workspace/runtime 単位にするか、この挙動を KDoc/PR に明記すると安全です。publishDevtoolsSocketNameは opt-in OFF やアプリ pid 変更後も.and-code/browser-devtools.txtを残します(BrowserOpenCommand.kt:64-76,118-120)。_published_devtools_socketの listen 確認で誤接続は防げますが、共有ストレージのワークスペースでは他アプリからもソケット名が読めるため、opt-out 時にファイルを削除するのが望ましいです。_read_http_bodyは今回の実機バグの再発防止に直結する一方、自動テストがありません(andcode-browser-mcp.py:81-123)。Content-Length / chunked / keep-alive(接続が開いたまま)を stdlib の unittest で数ケース追加し、CI のpython -m py_compile対象にapp/src/main/assets/scripts/andcode-browser-mcp.pyも加えると、同種の退行を CI で止められます。GuestBrowserScreenInstrumentedTestはinitialUrl = ""で開くため、端末上に last URL が保存済みだとそれを復元してテストが状態依存になり得ます(CI では instrumentation を実行していないので現状の影響は小)。テスト前にguest_browserprefs を clear するか、ストアを注入できるとより堅牢になります。チェック済み項目
git fetch origin main後にgit diff origin/main...HEADの全7ファイル・全hunkを確認(スクリプト1、新規Kotlin1、既存Kotlin2、NavGraph1、テスト2)。_read_http_body: ヘッダと本文の分割受信、Content-Length 完読、chunked(サイズ行・データ末尾CRLF・0終端)、keep-alive(接続を閉じない)を机上トレースし、旧data.endswith(b"]")によるタイムアウト原因が解消されることを確認。_published_devtools_socket: ファイル名・接頭辞検証・abstract socket(\0+ name)の接続確認、および_find_devtools_socketが「公開名を優先し、未接続時のみ/proc/net/unixへフォールバック」することを確認。.and-code/browser-devtools.txtとwebview_devtools_remote_<pid>の形式が一致。publishDevtoolsSocketNameが agent-control opt-in 時のみ呼ばれ、GuestWebContentのsetWebContentsDebuggingEnabled(agentControlEnabled)と同じフラグであることを確認。GuestBrowserLastUrl: http/https のみ保存・復元、非Web URL は既存値を保持、about:blank等を弾くこと、InMemorySharedPreferencesを使った5テストでカバーされていることを確認。BrowserCommandWatcherTestの新テストはapp/build.gradle.ktsのunitTests.isReturnDefaultValues = trueによりProcess.myPid()が 0 を返すため JVM テストで通ることを確認(app/build.gradle.kts:204-208)。git diff --checkクリーン、import 順・命名・KDoc は既存規約に沿う。GuestBrowserLastUrlは ViewModel の依存追加ではないため Koin / ViewModelFactory の同期は不要。