From b5f88030105664dff1bc319d9f325762cf2ef70b Mon Sep 17 00:00:00 2001 From: Tim Lander Date: Thu, 23 May 2019 13:58:45 +0800 Subject: [PATCH] Revert "emrun stability improvements (#8456)" This reverts commit 629390f171f2bbba6d62ae8ecbf419d65de8fa1d. --- emrun.py | 4 ++-- src/emrun_postjs.js | 31 ++++++++++++------------------- tests/browser_reporting.js | 2 +- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/emrun.py b/emrun.py index 281ef42c7f1e..63cdd33ba959 100755 --- a/emrun.py +++ b/emrun.py @@ -344,8 +344,8 @@ def kill_browser_process(): temporary Firefox profile that was created, if one exists.""" global browser_process, processname_killed_atexit, emrun_options, ADB if browser_process: - logv('Terminating browser process..') try: + logv('Terminating browser process..') browser_process.kill() delete_emrun_safe_firefox_profile() except Exception as e: @@ -1645,7 +1645,7 @@ def run(cmd): httpd = HTTPWebServer((options.hostname, options.port), HTTPHandler) if not options.no_browser: - logi("Starting browser: %s" % ' '.join(browser)) + logi("Executing %s" % ' '.join(browser)) # if browser[0] == 'cmd': # Workaround an issue where passing 'cmd /C start' is not able to detect when the user closes the page. # serve_forever = True diff --git a/src/emrun_postjs.js b/src/emrun_postjs.js index 38f8a0d54efe..fd5e558ce980 100644 --- a/src/emrun_postjs.js +++ b/src/emrun_postjs.js @@ -12,16 +12,17 @@ if (typeof window === "object" && (typeof ENVIRONMENT_IS_PTHREAD === 'undefined' var emrun_should_close_itself = false; function postExit(msg) { var http = new XMLHttpRequest(); - // Don't do this immediately, this may race with the notification about the return code reaching the - // server. Send a *sync* xhr so that we know for sure that the server has gotten the return code - // before we continue. - http.open("POST", "stdio.html", false); + http.onreadystatechange = function() { + if (http.readyState == 4 /*DONE*/) { + try { + // Try closing the current browser window, since it exit()ed itself. This can shut down the browser process + // and emrun does not need to kill the whole browser process. + if (typeof window !== 'undefined' && window.close) window.close(); + } catch(e) {} + } + } + http.open("POST", "stdio.html", true); http.send(msg); - try { - // Try closing the current browser window, since it exit()ed itself. This can shut down the browser process - // and then emrun does not need to kill the whole browser process. - window.close(); - } catch(e) {} } function post(msg) { var http = new XMLHttpRequest(); @@ -44,16 +45,8 @@ if (typeof window === "object" && (typeof ENVIRONMENT_IS_PTHREAD === 'undefined' out = function emrun_print(text) { post('^out^'+(emrun_http_sequence_number++)+'^'+encodeURIComponent(text)); prevPrint(text); } err = function emrun_printErr(text) { post('^err^'+(emrun_http_sequence_number++)+'^'+encodeURIComponent(text)); prevErr(text); } - // Notify emrun web server that this browser has successfully launched the page. Note that we may need to - // wait for the server to be ready. - function tryToSendPageload() { - try { - post('^pageload^'); - } catch (e) { - setTimeout(tryToSendPageload, 50); - } - } - tryToSendPageload(); + // Notify emrun web server that this browser has successfully launched the page. + post('^pageload^'); } } diff --git a/tests/browser_reporting.js b/tests/browser_reporting.js index 5d94791a2722..376b8ad2859e 100644 --- a/tests/browser_reporting.js +++ b/tests/browser_reporting.js @@ -28,7 +28,7 @@ function reportErrorToServer(message) { if (typeof window === 'object' && window) { window.addEventListener('error', function(e) { var xhr = new XMLHttpRequest(); - xhr.open('GET', encodeURI('http://localhost:8888?exception=' + e.message + ' / ' + e.stack)); + xhr.open('GET', encodeURI('http://localhost:8888?exception=' + e.message + ' / ' + e.target)); xhr.send(); }); }