Explorar o código

use `_pywebio_debug` query argument to set frontend debug mode

wangweimin %!s(int64=5) %!d(string=hai) anos
pai
achega
ccb304eb32
Modificáronse 1 ficheiros con 14 adicións e 7 borrados
  1. 14 7
      pywebio/html/index.html

+ 14 - 7
pywebio/html/index.html

@@ -55,16 +55,22 @@
 <script src="https://cdn.jsdelivr.net/npm/bs-custom-file-input/dist/bs-custom-file-input.js"></script>
 
 <script>
+    // https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
+    function getParameterByName(name, url) {
+        if (!url) 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, ' '));
+    }
 
     /*
     * Check given `backend_addr` is a http backend
     * Usage:
-    *   is_http_backend('http://localhost:8080/io').then(function(http_backend){
-    *        if(http_backend)
-    *               //
-    *        else
-    *               //
-    *   });
+    *   // `http_backend` is a boolean to present whether or not a http_backend the given `backend_addr` is
+    *   is_http_backend('http://localhost:8080/io').then(function(http_backend){ });
     * */
     function is_http_backend(backend_addr) {
         if (!backend_addr.startsWith('http://') && !backend_addr.startsWith('https://'))
@@ -95,6 +101,7 @@
 
     var md_body = $('#markdown-body');
 
+    const debug = getParameterByName('_pywebio_debug');
     is_http_backend('http://localhost:8080/io').then(function (http_backend) {
         var session;
         if (http_backend)
@@ -102,7 +109,7 @@
         else
             session = new WebIO.WebSocketWebIOSession(get_ws_addr());
         var ctrl = new WebIO.WebIOController(session, md_body, $('#input-container'));
-        session.start_session();
+        session.start_session(debug);
     });