From 856225abe328c29e0741fdb3bdd0eb2cf2888da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Porras=20Campo?= Date: Tue, 9 Dec 2025 14:38:08 +0100 Subject: [PATCH] fix: handle race conditions accessing elements in DOM Fixed the browser to not appear to be 'ready' to set the body before the text to be set has been processed. Otherwise, because the content is set asynchronously in a browser after the call to browser.setText, it can be that the first call to document.readyState is done before the browser has processed the request to modify the page, and therefore document.readyState returns true even if the page has no content. To fix this, we check that the document has at least one element before asking for document.readyState. --- .../operations/hover/FocusableBrowserInformationControl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/hover/FocusableBrowserInformationControl.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/hover/FocusableBrowserInformationControl.java index 50c2b767e..bf6e43a84 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/hover/FocusableBrowserInformationControl.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/hover/FocusableBrowserInformationControl.java @@ -102,7 +102,7 @@ private void updateBrowserSize(final Browser browser) { Point hint = computeSizeHint(); setSize(hint.x, hint.y); - if (!"complete".equals(safeEvaluate(browser, "return document.readyState"))) { //$NON-NLS-1$ //$NON-NLS-2$ + if (!"complete".equals(safeEvaluate(browser, "return document.documentElement ? document.readyState : 'no content';"))) { //$NON-NLS-1$ //$NON-NLS-2$ UI.getDisplay().timerExec(200, () -> updateBrowserSize(browser)); return; }