From 27d81c4fe6887984cfadaba284741cdc4ad38825 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 20 Dec 2018 11:43:04 +0300 Subject: [PATCH] Send less commands over Chrome RDP --- .../java/org/teavm/chromerdp/ChromeRDPDebugger.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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; }