in reply to Re^4: webperl: fetching data over the web
in thread webperl: fetching data over the web

OK I'm back online. :)

I created the following page called weblib_demo.html inside the deflated zip-dir (webperl_prebuilt_v0.07-beta.zip) from your webpage:

<!doctype html> <html lang="en-us"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>WebPerl &lt;script&gt; Demos</title> <script type="text/javascript"> function xfetch(url) { var req = new XMLHttpRequest(); req.open('GET', 'http://localhost:5000/emperl.js', false); req.send(null); if(req.status == 200) { return req.responseText; } else { return "FAILED"; } } alert(xfetch('http://localhost:5000/emperl.js')); </script> <script src="webperl.js"></script> <!-- Please see the documentation at http://webperl.zero-g.net/using.h +tml --> <script type="text/perl"> use warnings; use strict; use WebPerl qw/js/; print js('window.xfetch("http://localhost:5000/emperl.js")'); </script> <!-- Optional STDOUT/STDERR text area (if you don't use this, output g +oes to Javascript console) --> <script> window.addEventListener("load", function () { document.getElementById('output') .appendChild( Perl.makeOutputTextarea() ); }); </script> </head> <body> <p>This is a demo of <a href="http://webperl.zero-g.net" target="_blan +k">WebPerl</a>!</p> <div id="output"></div> <div id="buttons"> <button id="my_button">Testing!</button> </div> </body> </html>
It shows the alert box from JS but the Perl execution blocks the tab till I get a "Tab crashed" message (in German) after a minute or so.

Reproducible in FF and chrome.

I'm suspecting it has to do with error handling of the deprecation warning.

I tried to copy the democode directory directly from github, but calling demo.html creates an endless loop of "Perl initializing" and "ended" messages.

I suppose the webperl versions are not compatible and I need to clone the whole github rep.

That's the messages I get on the console

127.0.0.1 - - [08/Nov/2018:18:33:51 +0100] "GET /webperl.js HTTP/1.1" +200 13452 "http://localhost:5000/democode/perlrunner.html" "Mozilla/5 +.0 (Windows NT 10.0; WOW64; rv:61.0) Gecko/20100101 Firefox/61.0" 127.0.0.1 - - [08/Nov/2018:18:33:51 +0100] "GET /emperl.js HTTP/1.1" 2 +00 404633 "http://localhost:5000/democode/perlrunner.html" "Mozilla/5 +.0 (Windows NT 10.0; WOW64; rv:61.0) Gecko/20100101 Firefox/61.0" 127.0.0.1 - - [08/Nov/2018:18:33:51 +0100] "GET /emperl.data HTTP/1.1" + 200 11957600 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:61.0) Geck +o/20100101 Firefox/61.0" 127.0.0.1 - - [08/Nov/2018:18:33:51 +0100] "GET /emperl.wasm HTTP/1.1" + 200 3743906 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:61.0) Gecko +/20100101 Firefox/61.0" 127.0.0.1 - - [08/Nov/2018:18:33:51 +0100] "GET /emperl.wasm HTTP/1.1" + 200 3743906 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:61.0) Gecko +/20100101 Firefox/61.0" 127.0.0.1 - - [08/Nov/2018:18:33:51 +0100] "GET /democode/perlrunner.h +tml HTTP/1.1" 200 6168 "http://localhost:5000/democode/demo.html" "Mo +zilla/5.0 (Windows NT 10.0; WOW64; rv:61.0) Gecko/20100101 Firefox/61 +.0" 127.0.0.1 - - [08/Nov/2018:18:33:52 +0100] "GET /webperl.js HTTP/1.1" +200 13452 "http://localhost:5000/democode/perlrunner.html" "Mozilla/5 +.0 (Windows NT 10.0; WOW64; rv:61.0) Gecko/20100101 Firefox/61.0" 127.0.0.1 - - [08/Nov/2018:18:33:52 +0100] "GET /emperl.js HTTP/1.1" 2 +00 404633 "http://localhost:5000/democode/perlrunner.html" "Mozilla/5 +.0 (Windows NT 10.0; WOW64; rv:61.0) Gecko/20100101 Firefox/61.0" 127.0.0.1 - - [08/Nov/2018:18:33:52 +0100] "GET /emperl.data HTTP/1.1" + 200 11957600 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:61.0) Geck +o/20100101 Firefox/61.0" 127.0.0.1 - - [08/Nov/2018:18:33:52 +0100] "GET /emperl.wasm HTTP/1.1" + 200 3743906 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:61.0) Gecko +/20100101 Firefox/61.0" Terminating on signal SIGINT(2)

I think creating a new zip including the "democode" stuff would be helpful for causal tests.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^6: webperl: fetching data over the web
by haukex (Archbishop) on Nov 08, 2018 at 18:06 UTC

    Thank you, with that HTML file I can reproduce it too. (BTW, req.open('GET', 'http://localhost:5000/emperl.js', false); should probably be req.open('GET', url, false);)

    emperl.js is pretty huge, so I tried changing it to webperl.js, and although it exhibited the same behavior of seeming to block the webpage, after a little while it got unstuck and displayed the output. If you do print length(js(...)) instead of print js(), you get a result much quicker. The same is true if you remove the <textarea> from the HTML page, which causes the output to go to the JS console. There is obviously something very inefficient going on with the <textarea>, I'll take a guess that it's this line: ta.value = ta.value + str;.

    I didn't put a lot of effort into optimizing the STDOUT/ERR routines because in the WebPerl applications I was imagining, there wouldn't be any console output, and everything would get handled through the UI. But in the case of this textarea, there's certainly a lot of room for improvement. (Patches welcome :-) )

    The endless loop of initializing/ended is also interesting, something I haven't seen yet, could you tell me the steps to reproduce that?

      running in Edge gives more hints

      weblib_demo.html ...

      prints this output into the textarea

      wasm streaming compile failed: CompileError: Function body too big falling back to ArrayBuffer instantiation failed to asynchronously prepare wasm: CompileError: Function body too + big CompileError: Function body too big CompileError: Function body too big

      plus a popup "Perl Aborted"

      democode/demo.html ...

      does 2-4 popups saying "Perl aborted"

      I also have the feeling that a reload doesn't do a reset of the Perl engine.

      > should probably be req.open('GET', url, false);

      Indeed, fixed :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        Unfortunately I'm not all too surprised IE/Edge has some issues :-/ Unless I have confirmation otherwise, I'm going to assume it's a bug in the browser ;-)

      > The endless loop of initializing/ended is also interesting, something I haven't seen yet, could you tell me the steps to reproduce that? NB demo.html not index.html like in the online version.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        Thank you! The error I get on the JS console is: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:5000/emperl.wasm. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). I addressed that issue in 4a7dd5709b, which is unfortunately not part of v0.07-beta.

        For development, I would suggest this instead:

        $ git clone https://github.com/haukex/webperl.git $ wget https://github.com/haukex/webperl/releases/download/v0.07-beta/ +webperl_prebuilt_v0.07-beta.zip $ unzip webperl_prebuilt_v0.07-beta.zip $ cp webperl_prebuilt_v0.07-beta/emperl.* webperl/web/ $ cd webperl $ plackup web/webperl.psgi

        Then browse to http://localhost:5000/democode/demo.html.

      > There is obviously something very inefficient going on with the <textarea>, I'll take a guess that it's this line: ta.value = ta.value + str;.

      I've testet it in pure JS inside your webperl/plack environment.

      Adding the whole of emperl.js to a textarea works without problem in my FF.

      But appending 3000 lines in a loop creates an "out of memory" exception (adding only half the lines still works)

      So buffering output (think $| ) might be a solution.

      I'm expecting your ta.scrollTop = ta.scrollHeight; to mean even more trouble. *

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      *) indeed scrolling makes the whole unresponsive with much smaller line-counts already.

        What's even worse is that Emscripten may decide to provide the STDOUT stream on a character-by-character basis! (I don't think there's a clear spec on its behavior, i.e. whether it's characters or blocks.)