Skip to content

feat: add WebView Plugin API#2525

Draft
RohitKushvaha01 wants to merge 4 commits into
Acode-Foundation:mainfrom
RohitKushvaha01:feat/webview-plugin-api
Draft

feat: add WebView Plugin API#2525
RohitKushvaha01 wants to merge 4 commits into
Acode-Foundation:mainfrom
RohitKushvaha01:feat/webview-plugin-api

Conversation

@RohitKushvaha01

@RohitKushvaha01 RohitKushvaha01 commented Jul 22, 2026

Copy link
Copy Markdown
Member

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

Pre/Post Merge To-do:

  • Plugin types updation.
  • Plugin Docs updation.

Closes #2281

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-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds an API for plugins to create and manage isolated Android WebViews. The main changes are:

  • An acode.webview JavaScript and TypeScript API.
  • Fullscreen, window, panel, and hidden display modes.
  • URL and HTML loading, script evaluation, and bidirectional messaging.
  • Native lifecycle events and WebView cleanup.

Confidence Score: 4/5

This is close, but the initial visibility behavior should be fixed before merging.

  • visible: false is forwarded by JavaScript but ignored by native creation.
  • Window and panel WebViews can appear immediately when callers requested them to start hidden.

src/plugins/webview/src/android/com/foxdebug/webview/WebViewPlugin.java

Important Files Changed

Filename Overview
src/lib/webview.js Adds the public WebView wrapper, lifecycle listeners, messaging, and native action methods.
src/plugins/webview/src/android/com/foxdebug/webview/WebViewPlugin.java Adds native instance management, but the creation path ignores the requested initial visibility.
src/plugins/webview/src/android/com/foxdebug/webview/WebViewInstance.java Implements WebView configuration, attachment, navigation, messaging, downloads, and cleanup.
src/plugins/webview/src/android/com/foxdebug/webview/WebViewActivity.java Adds the activity used to host fullscreen WebView instances.

Reviews (3): Last reviewed commit: "fix: lifecycle events, hidden show, full..." | Re-trigger Greptile

Comment thread src/lib/webview.js Outdated
Comment thread src/plugins/webview/src/android/com/foxdebug/webview/WebViewPlugin.java Outdated
Comment thread src/plugins/webview/src/android/com/foxdebug/webview/WebViewPlugin.java Outdated
Comment on lines +108 to +120
" 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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Comment thread src/plugins/webview/src/android/com/foxdebug/webview/WebViewInstance.java Outdated
@RohitKushvaha01
RohitKushvaha01 marked this pull request as draft July 22, 2026 13:35
- 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)
@RohitKushvaha01

Copy link
Copy Markdown
Member Author

@greptile ai

webviewId = intent.getStringExtra("webviewId");

WebViewInstance instance = plugin != null ? plugin.getInstance(webviewId) : null;
if (instance == null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Initial Visibility Is Ignored

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Plugin API] Api to create webview instances

1 participant