diff --git a/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java b/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java index 6b96b92f4..a8fffa011 100644 --- a/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java +++ b/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java @@ -81,6 +81,7 @@ public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeC private ConcurrentMap> responseHandlers = new ConcurrentHashMap<>(); private ConcurrentMap> promises = new ConcurrentHashMap<>(); private AtomicInteger messageIdGenerator = new AtomicInteger(); + private Promise runtimeEnabledPromise; private List getListeners() { return new ArrayList<>(listeners); @@ -121,7 +122,7 @@ public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeC } private Promise injectFunctions(int contextId) { - return callMethodAsync("Runtime.enable", void.class, null) + return enableRuntime() .thenAsync(v -> { CompileScriptCommand compileParams = new CompileScriptCommand(); compileParams.expression = "$dbg_class = function(obj) { return typeof obj === 'object' " @@ -140,6 +141,13 @@ public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeC }); } + private Promise enableRuntime() { + if (runtimeEnabledPromise == null) { + runtimeEnabledPromise = callMethodAsync("Runtime.enable", void.class, null); + } + return runtimeEnabledPromise; + } + private ChromeRDPExchangeListener exchangeListener = messageText -> { callInExecutor(() -> receiveMessage(messageText) .catchError(e -> { @@ -225,6 +233,9 @@ public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeC } private Promise scriptParsed(ScriptParsedNotification params) { + if (params.getUrl() == null) { + return Promise.VOID; + } if (scripts.putIfAbsent(params.getScriptId(), params.getUrl()) != null) { return Promise.VOID; }