-
Notifications
You must be signed in to change notification settings - Fork 183
Closed
Labels
Milestone
Description
Summary
Edge Browser
freezes indefinitely when launching one Browser ("child" Browser) from another ("parent" Browser) via a BrowserFunction
using Display#syncExec
to create the child Browser. The same behavior is not exhibited when the child Browser is created within a Display#asyncExec
call.
Also want to note when SWT gets into this waiting state, closing the window does not kill the process. The process will run until killed manually.
Code To Reproduce
package snippets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.BrowserFunction;
import org.eclipse.swt.browser.ProgressAdapter;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
@SuppressWarnings({ "javadoc", "nls" })
public class EdgeSnippet
{
private static Display display;
private static Shell shell;
public static void main(String[] args)
{
display = new Display();
shell = new Shell(display);
shell.setLayout(new FillLayout());
Browser parentBrowser = new Browser(shell, SWT.EDGE);
parentBrowser.setText("<!DOCTYPE html> \n"
+ "<html>\n"
+ "<head> \n"
+ "</head> \n"
+ "<body>\n"
+ " <button onclick = \"openChildBrowser()\"> Open child browser </button> \n"
+ " <p> \n"
+ " <div id = \"result\"> </div> \n"
+ " </p> \n"
+ "</body> \n"
+ "</html>");
parentBrowser.addProgressListener(new ProgressAdapter()
{
@Override
public void completed(ProgressEvent event)
{
new OpenChildBrowserBrowserFunction(parentBrowser, "openChildBrowser");
}
});
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
private static class OpenChildBrowserBrowserFunction extends BrowserFunction
{
public OpenChildBrowserBrowserFunction(Browser browser, String name)
{
super(browser, name);
}
@Override
public Object function(Object[] arguments)
{
// If the following line is changed to asyncExec, the code executes just fine
display.syncExec(() ->
{
System.out.println("Opening Child Shell");
Shell childShell = new Shell(shell);
childShell.setLayout(new FillLayout());
childShell.setText("Child Browser");
Browser childBrowser = new Browser(childShell, SWT.EDGE);
childBrowser.setText("<!DOCTYPE html> \n"
+ "<html>\n"
+ "<head> \n"
+ "</head> \n"
+ "<body>\n"
+ " <p> \n"
+ " Child browser"
+ " </p> \n"
+ "</body> \n"
+ "</html>");
childShell.pack();
childShell.open();
});
return null;
}
}
}
Stack Trace
SWT waits indefinitely on the org.eclipse.swt.internal.win32.OS.WaitMessage call below:
org.eclipse.swt.internal.win32.OS.WaitMessage(Native Method)
org.eclipse.swt.widgets.Display.sleep(Display.java:4752)
org.eclipse.swt.browser.Edge.callAndWait(Edge.java:227)
org.eclipse.swt.browser.Edge.create(Edge.java:342)
org.eclipse.swt.browser.Browser.<init>(Browser.java:99)
snippets.EdgeSnippet$OpenChildBrowserBrowserFunction.lambda$0(EdgeSnippet.java:76)
org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:183)
org.eclipse.swt.widgets.Display.syncExec(Display.java:4785)
snippets.EdgeSnippet$OpenChildBrowserBrowserFunction.function(EdgeSnippet.java:68)
org.eclipse.swt.browser.Edge.handleCallJava(Edge.java:543)
org.eclipse.swt.internal.win32.OS.DispatchMessage(Native Method)
org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3640)
snippets.EdgeSnippet.main(EdgeSnippet.java:49)
Expected behavior
The child Browser opens successfully.
Environment:
- Select the platform(s) on which the behavior is seen:
- All OS
- Windows
- Linux
- macOS
- Additional OS info (e.g. OS version, Linux Desktop, etc)
Windows 10, also observed on Windows Server 2016 - JRE/JDK version
JDK 11.0.14.1
Version since
SWT 3.117-Current (3.123 at the time of writing this)
Known Workarounds
- Make either the parent, child, or both Browser(s) non-Edge Browser(s)
- Use
Display#asyncExec
instead ofDisplay#syncExec
to create the child Browser