Question regarding URL Parameters

Hi Community,

I try to pass an URL with Parameters in WebViewer. This does not work. If I omit this parameters URL can be shown. With the parameter ID I get the following runtime error. I testet HTML file on PC Browser and it works.

java.lang.IllegalArgumentException: URI has a query component at java.io.File.<init>(File.java:435) at com.google.appinventor.components.runtime.util.FileUtil.openFile(FileUtil.java:315) at com.google.appinventor.components.runtime.Form.openAssetInternal(Form.java:3088) at com.google.appinventor.components.runtime.Form.openAsset(Form.java:3049) at com.google.appinventor.components.runtime.util.HoneycombWebViewClient.handleAppRequest(HoneycombWebViewClient.java:65) at com.google.appinventor.components.runtime.util.HoneycombWebViewClient.shouldInterceptRequest(HoneycombWebViewClient.java:50) at WV.wg.a(chromium-SystemWebViewGoogle.aab-stable-772713701:103) at org.chromium.android_webview.ShouldInterceptRequestMediator.shouldInterceptRequestFromNative(chromium-SystemWebViewGoogle.aab-stable-772713701:18)
Note: You will not see another error reported for 5 seconds.

The aia file is…

TestURLParam_V01.aia (2.6 KB)

Can you please help me? Does the WebViewer Component does not support URL Parameters? Thanks in advance…

Best Regards

Yes, won't work with localhost because this is interpreted as a filename available in the assets.

Works when served from a normal url.

You could write some additional code to pass the parameter as a webviewstring if localhost is in the url.

1 Like

Thank you :slight_smile:

Something like this:

<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <title>Parameter Beispiel</title>
</head>
<body>

    <h1>Willkommen, <span id="ID">ID</span>!</h1>

    <script>

        if (AppInventor) {  
          var wvs = window.AppInventor.getWebViewString().split(",");        
          if (wvs[0].includes("localhost")) {
          document.getElementById('ID').textContent = wvs[1];
          } else {
        	    const urlParams = new URLSearchParams(window.location.search);
                const myID = urlParams.get('ID');
                document.getElementById('ID').textContent = myID;
          }
        } else {
            const urlParams = new URLSearchParams(window.location.search);
            const myID = urlParams.get('ID');
            document.getElementById('ID').textContent = myID;
        }
    </script>
</body>
</html>

Should work in AppInventor and on computers

1 Like

Thanks for your AddOn :slight_smile: I put all together to my personal WiKi-Document (meanwhile I have serval ones…: JavaScript, AI2, Arduino, C++, FreeCAD, general technical stuff, VBA…