User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: WebView2 JavaScript doesn't work when page is remotely loaded

  1. #1
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    WebView2 JavaScript doesn't work when page is remotely loaded

    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:

    Code:
    <html>
    <head>
    <script type="text/javascript">
        window.download_url = "https://example.com";
    window.license_url = "/generate-license.php?act=4";
        
        function GetResponse(code) {
            return code + ' test';
        }
        alert(GetResponse('internal test'));
    </script>
    </head>
    <body>
        <h1>Thank you!</h1>
        <p>Signup complete, please wait for installer to start!</p>
    </body>
    </html>
    It should show an alert box on page load (and on regular browsers or loaded from HTML locally in WebView2).

  2. #2
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Fernando any ideas?

  3. #3
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,409
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    I tried it using the Brackets Live Preview to serve the file, and it worked fine...

  4. #4
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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="https://dev.stonenotes.com:9443/thanks.php"

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

  5. #5
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

    Code:
    <html>
    <head>
    </head>
    <body>
    
    <form action="thanks.php" method="POST">
    <input type="text" name="test" />
    <input type="submit" />
    </form>
    
    </body>
    </html>
    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.

  6. #6
    Clickteam Clickteam
    Fernando's Avatar
    Join Date
    Dec 2006
    Posts
    7,057
    Mentioned
    298 Post(s)
    Tagged
    4 Thread(s)
    this seems to be a problem when mixing local and server side, post a small mfa that reproduce this for me to check
    Regards,


    Fernando Vivolo

    ... new things are coming ...

  7. #7
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Fernando,

    MFA attached. Thank you for looking into it.
    Attached files Attached files

  8. #8
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Fernando Hey just wanted to check and see if you were able to look into this.

  9. #9
    Clickteam Clickteam
    Fernando's Avatar
    Join Date
    Dec 2006
    Posts
    7,057
    Mentioned
    298 Post(s)
    Tagged
    4 Thread(s)
    Actually i will require more explanation to work with your mfa.

    hmm seems that GetReponse is not trigger at the right time
    Regards,


    Fernando Vivolo

    ... new things are coming ...

  10. #10
    Clicker

    Fusion 2.5 (Steam)Fusion 2.5+ DLC (Steam)

    Join Date
    Jan 2021
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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: https://www.stonenotes.com/test.php

    If you change the inital URL loaded in the Web View in the MFA to the result page, https://www.stonenotes.com/test-thanks.php then the alert box *does* appear.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 24th October 2017, 07:32 PM
  2. calling a function FROM page javascript
    By Chokito in forum HTML5 Export Module 2.5
    Replies: 1
    Last Post: 28th March 2014, 05:01 AM
  3. Create object "from a loaded application"...how does this work?
    By Warmachine in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 20th March 2014, 07:00 AM
  4. BETA 23: Virtual width & layer wrapping not even remotely working XD
    By DistantJ in forum Android Export Module Version 2.0
    Replies: 2
    Last Post: 25th March 2012, 03:48 PM
  5. ActiveX IE Browser page loaded
    By crugh in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 23rd October 2007, 01:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •