WebViewStringChange block issue

Hello, I found a problem with the WebViewStringChange block in the WebViewer component
I was able to run the site from the asset (in iOS) but did not get a response from WebViewStringChange.

(It works fully on Android - you should get the text you typed on the keyboard in label 1)
In addition, I noticed that no alerts are opened from the site (this should open a window when you click on the button displayed in the site viewer)
HTML.aia (2.7 KB)צילום מסך 2021-03-15 ב-21.21.29

Hmm. WebViewStringChange should have worked okay. Regarding the alert box, I think that is something separate we'll have to implement as the WKWebView doesn't do this natively--it's up to the browser/app to provide it. I've filed an issue with the corresponding AIA attached.

Well, I'm not getting a response.
I would love if you could look at the code (HTML) and blocks to see if there should be any issue with iOS

צילום מסך 2021-03-15 ב-21.21.29

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <input type="button" value="alert" onclick="action(window.prompt('Type...'),  false);">

    <script>
        action(getParameterByname('a'), true);

        function getParameterByname(name, url = window.location.href) {
            name = name.replace(/[\[\]]/g, '\\$&');
            var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
                results = regex.exec(url);
            if (!results) return null;
            if (!results[2]) return '';
            return decodeURIComponent(results[2].replace(/\ /g, ' '));
        }

        function action(a, apporweb) {
            if (apporweb)
                window.AppInventor.setWebViewString(a);
            else
                alert(a);
        }
    </script>

</body>
</html>

Hello Tomer

You can check HTML syntax here:

Your HTML code has a couple of minor syntax errors that do not have an effect on it's purpose.

Are you sure the paths to the file are correct? On Android we are now using:
http://localhost/myhtml.html
For both companion and build.
Alert works in a WebViewer on Android :grin:

The path to the file is correct, you can see that the site is loaded from the assets. Note that these are supposed to operate only at the companion.

I know, but it does not work in iOS

The problem was fixed after the last update (2.60.1) but I noticed that if I use one of the following characters (on the keyboard): space, ', ", ₪, {,}, €, £, ^,%
(in addition it also happens with characters in languages Miscellaneous and there may be other characters that this problem happens with) then I get this error:


I noticed that if I remove one of the problematic characters from the keyboard (after getting the initial error) I will get this error. (But this only happens in some characters):

  • The errors I mentioned are accepted in the web viewer

Are you putting the characters directly into the Url property or are you performing the redirect from the Javascript side?

I enter these characters from the URL property
(the characters are entered on the keyboard)
You can see it in this picture:

I don't think that they are valid characters though for a query string. You may need to percent encode using the Web's UrlEncode function.

1 Like

Thanks for the answer, it works now
I checked the same thing on Android and instead of a space character I get the + character (in iOS this does not happen).
Android:

IOS:

Although the problem can be easily solved, I think the initial problem needs to be fixed, as there is a different response between the platforms and we want the application to behave as similarly as possible on both platforms.

I believe the Android implementation is correct here because typically when you convert a string into a query string, spaces are replaced by +'s (see for example conducting a search in your favorite search engine). The iOS API for URI escaping might not be processing spaces but I'd have to check the documentation.

1 Like

thanks for sharing information