Skip to content

Commit 3d459ab

Browse files
committed
Edge: Ensure #getText() works even when javascript is disabled
Fixes #2029.
1 parent 51b87c9 commit 3d459ab

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,14 @@ public Object evaluate(String script) throws SWTException {
916916
// Feature in WebView2. ExecuteScript works regardless of IsScriptEnabled setting.
917917
// Disallow programmatic execution manually.
918918
if (!jsEnabled) return null;
919+
return evaluateInternal(script);
920+
}
921+
922+
/**
923+
* Unconditional script execution, bypassing {@link WebBrowser#jsEnabled} flag /
924+
* {@link Browser#setJavascriptEnabled(boolean)}.
925+
*/
926+
private Object evaluateInternal(String script) throws SWTException {
919927
if(inCallback > 0) {
920928
// Execute script, but do not wait for async call to complete as otherwise it
921929
// can cause a deadlock if execute inside a WebView callback.
@@ -965,7 +973,7 @@ String getJavaCallDeclaration() {
965973

966974
@Override
967975
public String getText() {
968-
return (String)evaluate("return document.documentElement.outerHTML;");
976+
return (String)evaluateInternal("return document.documentElement.outerHTML;");
969977
}
970978

971979
@Override

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,18 @@ public void test_getText_html() {
17461746
getText_helper(testString, testString);
17471747
}
17481748

1749+
/**
1750+
* Ensure getText() works even if consumer-level scripting is disabled. Needed
1751+
* on platforms where getText() implementation is JavaScript-based, e.g. Edge:
1752+
* https://github.com/eclipse-platform/eclipse.platform.swt/issues/2029
1753+
*/
1754+
@Test
1755+
public void test_getText_javscriptDisabled() {
1756+
browser.setJavascriptEnabled(false);
1757+
String testString = "<html><head></head><body>hello<b>World</b></body></html>";
1758+
getText_helper(testString, testString);
1759+
}
1760+
17491761
/** Ensure we get webpage before javascript processed it.
17501762
* E.g JS would add 'style' tag to body after processing. */
17511763
@Test

0 commit comments

Comments
 (0)