-
Notifications
You must be signed in to change notification settings - Fork 17
DRAFT: feat: webview commands for listing and evaluating js #229
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
gmegidish
wants to merge
23
commits into
main
Choose a base branch
from
feat/webview
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 15 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
9ce4f38
feat: add device.webview.* method stubs
gmegidish 8dabdb1
feat: align webview methods with trimmed OpenRPC spec
gmegidish 3945a67
feat: add webview CLI commands
gmegidish 36729b8
feat: implement WebViewListCommand for Android
gmegidish cef8b30
fix: remove hardcoded DEX_PATH from jvmti_agent.c
gmegidish 559d39d
feat: implement webview goto, evaluate (url + title) for Android
gmegidish a6e7d1e
fix: webview url/title/eval returning empty result
gmegidish 37687ee
feat: implement webview back, forward, content
gmegidish d8109a6
fix: ensure bare expressions are wrapped with return in WebViewEvaluate
gmegidish 46f452c
feat: implement webview reload
gmegidish e6a0c33
fix: handle null evalJs result and ClassCastException in evaluateExpr…
gmegidish 98d936d
build: wire agents/android into root Makefile
gmegidish 7808755
feat: implement webview waitForLoadState
gmegidish 31386a7
refactor: replace map[string]any with typed result structs
gmegidish 4abe35b
chore: add agent sources, Makefile, and adb client
gmegidish f42b53c
chore: remove built agent binaries from git, add to gitignore
gmegidish 581330f
fix: cross-platform agent Makefile and CI agent build job
gmegidish b1cfde6
feat: iOS simulator webview agent (list, url, goto)
gmegidish c6d1eea
no dylib in git
gmegidish 49d63ee
feat: complete iOS simulator webview support + WebViewable interface
gmegidish c74d7b7
feat: iOS real device webview list (inject via lldb, forward via go-ios)
gmegidish c0e2d01
fix: iOS 26 SDK compat for real device webview injection via LLDB
gmegidish 0391621
performance
gmegidish 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package agents | ||
|
|
||
| import _ "embed" | ||
|
|
||
| //go:embed android/devicekit.so | ||
| var AndroidDevicekitSO []byte | ||
|
|
||
| //go:embed android/devicekit.dex | ||
| var AndroidDevicekitDEX []byte | ||
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,28 @@ | ||
| NDK := $(HOME)/Library/Android/sdk/ndk/29.0.13113456 | ||
| TOOLCHAIN := $(NDK)/toolchains/llvm/prebuilt/darwin-x86_64/bin | ||
| CC_ANDROID := $(TOOLCHAIN)/aarch64-linux-android26-clang | ||
| JDK_INC := $(shell brew --prefix openjdk@21)/include | ||
| SYSROOT := $(NDK)/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include | ||
| JAVAC := $(shell brew --prefix openjdk@21)/bin/javac | ||
| D8 := $(HOME)/Library/Android/sdk/build-tools/36.0.0/d8 | ||
| ANDROID_JAR := $(HOME)/Library/Android/sdk/platforms/android-35/android.jar | ||
|
|
||
| JAVA_SRCS := $(wildcard java/*.java) | ||
|
|
||
| all: devicekit.so devicekit.dex | ||
|
|
||
| devicekit.so: jvmti_agent.c | ||
| $(CC_ANDROID) -shared -fPIC -O2 \ | ||
| -I$(SYSROOT) -I$(JDK_INC) -I$(JDK_INC)/darwin \ | ||
| -o $@ $< -llog | ||
|
|
||
| devicekit.dex: $(JAVA_SRCS) | ||
| mkdir -p .dex_build | ||
| $(JAVAC) --release 8 -cp $(ANDROID_JAR) -d .dex_build $(JAVA_SRCS) | ||
| $(D8) --min-api 26 --output .dex_build $$(find .dex_build -name "*.class") | ||
| mv .dex_build/classes.dex devicekit.dex | ||
| rm -rf .dex_build | ||
|
|
||
| clean: | ||
| rm -f devicekit.so devicekit.dex | ||
| rm -rf .dex_build |
Binary file not shown.
Binary file not shown.
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,107 @@ | ||
| package com.mobilenext.mobilecli; | ||
|
|
||
| import android.os.Handler; | ||
| import android.os.Looper; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.webkit.WebView; | ||
|
|
||
| import java.lang.reflect.Field; | ||
| import java.util.List; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.stream.IntStream; | ||
| import java.util.stream.Stream; | ||
|
|
||
| class AndroidBridge { | ||
|
|
||
| static Handler sMainHandler; | ||
|
|
||
| private static String sPackageName; | ||
| private static Field sMViewsField; | ||
| private static Object sWmgInstance; | ||
|
|
||
| static void init() { | ||
| sMainHandler = new Handler(Looper.getMainLooper()); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| static List<View> getRootViews() throws Exception { | ||
| if (sMViewsField == null) { | ||
| Class<?> wmgClass = Class.forName("android.view.WindowManagerGlobal"); | ||
| sMViewsField = wmgClass.getDeclaredField("mViews"); | ||
| sMViewsField.setAccessible(true); | ||
| sWmgInstance = wmgClass.getMethod("getInstance").invoke(null); | ||
| } | ||
| return (List<View>) sMViewsField.get(sWmgInstance); | ||
| } | ||
|
|
||
| static String getPackageName() { | ||
| if (sPackageName != null) { | ||
| return sPackageName; | ||
| } | ||
| try { | ||
| byte[] buf = new byte[256]; | ||
| java.io.FileInputStream fis = new java.io.FileInputStream("/proc/self/cmdline"); | ||
| int len = fis.read(buf); | ||
| fis.close(); | ||
| int end = 0; | ||
| while (end < len && buf[end] != 0 && buf[end] != ':') { | ||
| end++; | ||
| } | ||
| sPackageName = new String(buf, 0, end).trim(); | ||
| return sPackageName; | ||
| } catch (Exception e) { | ||
| return "unknown"; | ||
| } | ||
| } | ||
|
|
||
| static Stream<WebView> streamWebViews(View view) { | ||
| if (view instanceof WebView) { | ||
| return Stream.of((WebView) view); | ||
| } else if (view instanceof ViewGroup) { | ||
| ViewGroup vg = (ViewGroup) view; | ||
| return IntStream.range(0, vg.getChildCount()) | ||
| .mapToObj(vg::getChildAt) | ||
| .flatMap(AndroidBridge::streamWebViews); | ||
| } | ||
| return Stream.empty(); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| static <T> T runOnMainThread(Callable<T> task) throws Exception { | ||
| Object[] result = {null}; | ||
| Exception[] err = {null}; | ||
| CountDownLatch latch = new CountDownLatch(1); | ||
| sMainHandler.post(() -> { | ||
| try { | ||
| result[0] = task.call(); | ||
| } catch (Exception e) { | ||
| err[0] = e; | ||
| } finally { | ||
| latch.countDown(); | ||
| } | ||
| }); | ||
| if (!latch.await(5, TimeUnit.SECONDS)) { | ||
| throw new Exception("timed out"); | ||
| } | ||
| if (err[0] != null) { | ||
| throw err[0]; | ||
| } | ||
| return (T) result[0]; | ||
| } | ||
|
|
||
| static String evalJs(WebView wv, String script) throws Exception { | ||
| String[] result = {null}; | ||
| CountDownLatch latch = new CountDownLatch(1); | ||
| sMainHandler.post(() -> wv.evaluateJavascript(script, value -> { | ||
| result[0] = value; | ||
| latch.countDown(); | ||
| })); | ||
| if (!latch.await(10, TimeUnit.SECONDS)) { | ||
| throw new Exception("evaluateJavascript timed out"); | ||
| } | ||
| return result[0]; | ||
| } | ||
| } |
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,67 @@ | ||
| package com.mobilenext.mobilecli; | ||
|
|
||
| import android.net.LocalServerSocket; | ||
| import android.net.LocalSocket; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.InputStreamReader; | ||
| import java.io.PrintWriter; | ||
|
|
||
| class HttpRpcServer { | ||
|
|
||
| static void start() { | ||
| String name = "mobilecli." + AndroidBridge.getPackageName(); | ||
| new Thread(() -> { | ||
| try { | ||
| LocalServerSocket server = new LocalServerSocket(name); | ||
| android.util.Log.d("MobileCliAgent", "listening on localabstract:" + name); | ||
| while (true) { | ||
| handleClient(server.accept()); | ||
| } | ||
| } catch (Exception e) { | ||
| android.util.Log.e("MobileCliAgent", "server error: " + e.getMessage()); | ||
| } | ||
| }, "vta-server").start(); | ||
| } | ||
|
|
||
| private static void handleClient(LocalSocket client) { | ||
| new Thread(() -> { | ||
| try ( | ||
| BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); | ||
| PrintWriter out = new PrintWriter(client.getOutputStream(), false) | ||
| ) { | ||
| String requestLine = in.readLine(); | ||
| if (requestLine == null) { | ||
| return; | ||
| } | ||
|
|
||
| int contentLength = 0; | ||
| String header; | ||
| while ((header = in.readLine()) != null && !header.isEmpty()) { | ||
| if (header.toLowerCase().startsWith("content-length:")) { | ||
| contentLength = Integer.parseInt(header.substring(15).trim()); | ||
| } | ||
| } | ||
|
|
||
| char[] body = new char[contentLength]; | ||
| if (contentLength > 0) { | ||
| in.read(body, 0, contentLength); | ||
| } | ||
| String bodyStr = new String(body).trim(); | ||
|
|
||
| String response = JsonRpcDispatcher.dispatch(bodyStr.isEmpty() ? "{}" : bodyStr); | ||
|
|
||
| byte[] bytes = response.getBytes("UTF-8"); | ||
| out.print("HTTP/1.1 200 OK\r\n"); | ||
| out.print("Content-Type: application/json\r\n"); | ||
| out.print("Content-Length: " + bytes.length + "\r\n"); | ||
| out.print("Connection: close\r\n"); | ||
| out.print("\r\n"); | ||
| out.print(response); | ||
| out.flush(); | ||
| } catch (Exception e) { | ||
| android.util.Log.e("MobileCliAgent", "client error: " + e.getMessage()); | ||
| } | ||
| }, "vta-client").start(); | ||
| } | ||
| } |
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.
🧩 Analysis chain
🏁 Script executed:
Repository: mobile-next/mobilecli
Length of output: 1958
🏁 Script executed:
Repository: mobile-next/mobilecli
Length of output: 82
🏁 Script executed:
Repository: mobile-next/mobilecli
Length of output: 239
🏁 Script executed:
Repository: mobile-next/mobilecli
Length of output: 289
Missing embed targets cause compile failure
Both
android/devicekit.so(line 5) andandroid/devicekit.dex(line 8) are missing from the repository. The//go:embeddirectives will fail at build time until these artifacts are added.🧰 Tools
🪛 GitHub Check: test
[failure] 8-8:
pattern android/devicekit.dex: no matching files found
🤖 Prompt for AI Agents