From 3a265e0f52d9b8368108c3d32946c40b21c0136a Mon Sep 17 00:00:00 2001 From: Liang Jiaqing Date: Fri, 27 Feb 2026 11:47:06 +0800 Subject: [PATCH] feat: add await detection and friendly prompt (v0.32) - Detect await usage in sync context - Auto-wrap with async function - Return friendly prompt suggesting to avoid await - Provide alternative solution using global variables --- assets/ljq_web_driver.user.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/assets/ljq_web_driver.user.js b/assets/ljq_web_driver.user.js index c5642c8..4a52c7d 100644 --- a/assets/ljq_web_driver.user.js +++ b/assets/ljq_web_driver.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name ljq_web_driver // @namespace http://tampermonkey.net/ -// @version 0.31 +// @version 0.32 // @description Execute JS via ljq_web_driver // @require https://code.jquery.com/jquery-3.6.0.min.js // @author You @@ -310,6 +310,9 @@ } catch (e) { if (isIllegalReturnError(e)) { result = (new Function(jsCode))(); + } else if (isAwaitError(e)) { + result = (async function() { return eval(jsCode); })(); + result = 'Promise is running, cannot get return value. Suggest avoiding await next time, or use global variables (e.g., window.myVar) to store async results.'; } else throw e; } } @@ -336,6 +339,13 @@ ); } + function isAwaitError(e) { + return e instanceof SyntaxError && ( + /await is only valid in async/i.test(e.message) || // Chrome + /await.*async/i.test(e.message) // Firefoxç­‰ + ); + } + function connect() { ws = new WebSocket(wsUrl);