Skip to content

fix(android): webview URL with large GET data#14457

Open
m1ga wants to merge 2 commits into
mainfrom
androidWebViewUrl
Open

fix(android): webview URL with large GET data#14457
m1ga wants to merge 2 commits into
mainfrom
androidWebViewUrl

Conversation

@m1ga
Copy link
Copy Markdown
Contributor

@m1ga m1ga commented Jun 3, 2026

In one of my apps I'm using a webview to display two graphs. I wanted to prefill it with data when the page is set and tried to attach all of the data using $.www_chart.url = 'www/chart.html?data=' + encodeURIComponent(JSON.stringify(graphValues)) and my app was crashing:

[ERROR] TiAssetHelper: Error while opening asset "Resources/www/chart.html?data=[90.3,90.3,90.3,9....
[ERROR] TiAssetHelper:  at android.content.res.AssetManager.nativeOpenAsset(Native Method)
[ERROR] TiAssetHelper:  at android.content.res.AssetManager.open(AssetManager.java:1012)
[ERROR] TiAssetHelper:  at android.content.res.AssetManager.open(AssetManager.java:989)
[ERROR] TiAssetHelper:  at org.appcelerator.kroll.util.KrollAssetHelper.openAsset(KrollAssetHelper.java:136)
[ERROR] TiAssetHelper:  at org.appcelerator.titanium.io.TiResourceFile.getInputStream(TiResourceFile.java:70)
[ERROR] TiAssetHelper:  at ti.modules.titanium.ui.widget.webview.TiUIWebView.setUrl(TiUIWebView.java:595)
[ERROR] TiAssetHelper:  at ti.modules.titanium.ui.widget.webview.TiUIWebView.processProperties(TiUIWebView.java:413)

The issue is:

With large/encoded data (base64 +, /, =, URL-encoded chars), the extracted query string doesn't exactly match how it appears in finalUri.toString() after passing through the resolveUrl() pipeline. The replace silently fails, and the query leaks into the path passed to AssetManager.open("Resources/page.html?data=<HUGE_DATA>"). That file doesn't exist → "TiAssetHelper: Error while opening asset" → Null InputStream → uncaught NullPointerException crash.

Test (from an old ticket #11564 about URL query parameters):

index.html

<!DOCTYPE html>
<html>
    <body>
        <script>
            alert('query: ' + window.location.search);
        </script>
    </body>
</html>
const win = Ti.UI.createWindow();
const webView = Ti.UI.createWebView({
	url: 'app://index.html?data=1234'
        // url: '/index.html?data=1234'
        // url: 'file:///android_asset/Resources/index.html?data=1234'
});

win.add(webView);
win.open();

The fix works with 640 array points attached in the URL.

The Fix:
Fix 1 — Line 587: Replaced fragile finalUri.toString().replace(query, "") with finalUri.buildUpon().clearQuery().build().toString(). This uses Uri.Builder.clearQuery() to strip the query string properly, regardless of encoding or data size. Works for both local (file:///android_asset/...) and remote (https://...) URLs.

Fix 2 — Lines 596-598: Added null-check on the InputStream after tiFile.getInputStream(). If the asset can't be opened, it throws IOException instead of an uncaught NullPointerException, so the error is handled gracefully by the existing catch block and falls through to the direct WebView load path.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant