WebView2 JavaScript doesn't work when page is remotely loaded

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I have a page served by a server I have written in PHP. This also contains some JavaScript, which works correctly in a regular browser such as Chrome or IE, but does not work when loaded into the WebView2 control.

    If I copy the generated markup into a String and use LoadHTML on WebView2 rather than Load Page, the JavaScript suddenly works (without any changes).

    Any ideas how I can fix this or is this a bug?

    Here's the HTML result for reference:

    It should show an alert box on page load (and on regular browsers or loaded from HTML locally in WebView2).

  • It seems like my initial problem was trying to run JS in response to the page loading. When I removed that the dialog box also comes up from the internal alert call.

    However, I need to know when the page is done loading so I can then I trigger a call to the JS on the page to see what the result was. Any way I try to do this seems to cause the internal alert to never get called, and returns nothing to Fusion.

    It does seem to work fine if I use a button to trigger a JS call though. Really confusing.

    It seems like it's started to finally work as expected by calling a event through the timer:

    * Start of Frame
    WebView2 : Navigation mode=0
    WebView2 : Load URL="Please login to see this link."

    * WebView2: On Load complete
    Log : Add line "Load Complete"
    the timer : Fire event "CheckResponse" after 01''-00

    * On timer event "CheckResponse"
    Log : Add line "CheckResponse: " + CallFunctionString$( "WebView2", "GetResponse", "'result'" )

    We'll see if this keeps working and hopefully it'll help someone else some day.

  • Okay well I found another cause of the problem, which seems to be submitting a form (or maybe other types of navigation?).

    The JS code doesn't work when it's the second page loaded after a form submission.

    So if I load this page initially test.php, with the initial markup listed in the first post above at thanks.php:

    Then submit that form, thanks.php is loaded but the JS code on thanks.php never runs and I can't call JS functions on it even with the timer delay method (well I can but it just returns a blank string).

    If I load thanks.php directly with the timer method it is able to call the JS function and get back the expected values.

  • If you click the button on the first page, a js triggered dialog box should appear on the second page, but does not.

    You can see this working by visiting the page in a normal browser: Please login to see this link.

    If you change the inital URL loaded in the Web View in the MFA to the result page, Please login to see this link. then the alert box *does* appear.

  • Too late to edit my last message...

    If you remove the calls to CallFunctionString$ it does show the alert on the second page, but how else can I trigger a JS function call when the page is done loading?

    * WebView2: On Load complete
    Log : Add line "Load Complete " + GetNavigateURL$( "WebView2" )
    the timer : Fire event "CheckResponse" after 01''-00

    * On timer event "CheckResponse"
    Special : Set Response to CallFunctionString$( "WebView2", "GetResponse", "result" )
    Log : Add line "Response: " + Response

    This should log out a line line "Response: result test" in the List box but the result is instead "Response:" -- blank string.

    If the JS was invalid I'd expect the On Error condition of the WebView2 to be triggered, but it doesn't seem to be. So I'm at a loss at to what is causing these JS function calls to not work, and why attempting to use CallFunctionString$ causes the built-in JS to not load.

  • i see. you are triggering the time event incorrectly,

    may you try this way and check

    * WebView2: On Load complete
    Log : Add line "Load Complete " + GetNavigateURL$( "WebView2" )


    * WebView2: On Load complete
    + GetCurrentURL$( "WebView2" ) = "Please login to see this link."
    the timer : Fire event "CheckResponse" after 01''-00

    Regards,


    Fernando Vivolo

    ... new things are coming ...

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!