feat: add WebView Plugin API#2525
Conversation
Add cordova-plugin-acode-webview allowing plugins to create and manage isolated WebView instances with fullscreen, window, panel, and hidden modes. Features: - Create independent WebView instances via acode.webview.create() - Load URLs, HTML content, and execute JavaScript - Bidirectional messaging between plugin and WebView - Lifecycle management: show, hide, reload, destroy - Lifecycle events: pageFinished, titleChanged, closed
Fullscreen mode is now a clean full-screen WebView with no chrome. Back button handles navigation and closing.
Greptile SummaryThis PR adds an API for plugins to create and manage isolated Android WebViews. The main changes are:
Confidence Score: 4/5This is close, but the initial visibility behavior should be fixed before merging.
src/plugins/webview/src/android/com/foxdebug/webview/WebViewPlugin.java Important Files Changed
Reviews (3): Last reviewed commit: "fix: lifecycle events, hidden show, full..." | Re-trigger Greptile |
| " window.webview._callbacks = [];" + | ||
| " window.webview.onMessage = function(cb) { window.webview._callbacks.push(cb); };" + | ||
| " window.webview.postMessage = function(msg) {" + | ||
| " var data = typeof msg === 'string' ? msg : JSON.stringify(msg);" + | ||
| " window.AcodeWebViewNative.postMessage(data);" + | ||
| " };" + | ||
| " window.webview.offMessage = function(cb) {" + | ||
| " window.webview._callbacks = window.webview._callbacks.filter(function(c) { return c !== cb; });" + | ||
| " };" + | ||
| "})();"; | ||
|
|
||
| webView.evaluateJavascript(bridgeJs, null); | ||
| } |
There was a problem hiding this comment.
Navigation Removes Message Bridge
The page API is injected only into the initial blank document. loadURL(), loadHTML(), and later navigation replace that JavaScript context, but onPageFinished() never injects the API again, so loaded content has no window.webview and cannot send or receive messages.
- Fix event dispatch: filter callbacks by event name instead of
calling {event,callback} objects as functions (webview.js)
- Make hidden WebViews showable: attachToActivity() on first show()
- Remove universal file access (setAllowFileAccessFromFileURLs,
setAllowUniversalAccessFromFileURLs) for untrusted content
- Clean up fullscreen path: remove throwaway WebView in Activity,
register instance cleanup in onDestroy
- Add deprecated shouldOverrideUrlLoading(String) for compat
- Use Handler(Looper.getMainLooper()) instead of View.post()
so hidden WebViews can process loadURL/evaluate without a window
- Remove unused constructor params (title, x, y, initiallyVisible)
|
@greptile ai |
| webviewId = intent.getStringExtra("webviewId"); | ||
|
|
||
| WebViewInstance instance = plugin != null ? plugin.getInstance(webviewId) : null; | ||
| if (instance == null) { |
There was a problem hiding this comment.
Fullscreen still closes immediately.
WebViewActivity reads its private static plugin field, but the fullscreen launch path never calls setPlugin(). The field remains null, so creating a fullscreen WebView makes instance null and immediately finishes the activity without displaying any content. Initialize this reference before launching the activity or retrieve the initialized WebViewPlugin singleton.
| private void create(JSONObject options, final CallbackContext callbackContext) throws JSONException { | ||
| final String id = generateId(); | ||
| final String mode = options.optString("mode", "hidden"); | ||
| final int width = options.optInt("width", 0); |
There was a problem hiding this comment.
The JavaScript API still sends visible, but this creation path no longer reads it. Calling create({ mode: "window", visible: false }) therefore reaches attachToActivity() and displays the WebView immediately. Keep visibility separate from mode so initially hidden window and panel instances remain detached or hidden until show() is called.
Add cordova-plugin-acode-webview allowing plugins to create and manage isolated WebView instances with fullscreen, window, panel, and hidden modes.
Features:
Pre/Post Merge To-do:
Closes #2281