Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge Browser freezes indefinitely when launching one Browser from another via a BrowserFunction #669

Closed
1 of 4 tasks
daniemur opened this issue May 12, 2023 · 3 comments
Closed
1 of 4 tasks
Labels
edge Edge Browser Windows Happens on Windows OS
Milestone

Comments

@daniemur
Copy link

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:

  1. Select the platform(s) on which the behavior is seen:
  • All OS
  • Windows
  • Linux
  • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)
    Windows 10, also observed on Windows Server 2016
  2. JRE/JDK version
    JDK 11.0.14.1

Version since
SWT 3.117-Current (3.123 at the time of writing this)

Known Workarounds

  1. Make either the parent, child, or both Browser(s) non-Edge Browser(s)
  2. Use Display#asyncExec instead of Display#syncExec to create the child Browser
@HeikoKlare
Copy link
Contributor

The root cause for this behavior is that the WebView2 threading model does simply not allow this: https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/threading-model
All handlers and callbacks are processed sequentially. Triggering another event from within a callback (as done in the example) leads to a deadlock.

A potential solution option is to execute whatever code is embedded into a callback in an asynchronous way. But since the current browser API is expected to operate synchronously and return results rather than futures, this may easily break compatibility.

At least the Edge browser implementation usually checks for these kinds of deadlocks and throws an exception rather than actually running into a deadlock:

void checkDeadlock() {
// Feature in WebView2. All event handlers, completion handlers
// and JavaScript callbacks are serialized. An event handler waiting
// for a completion of another handler will deadlock. Detect this
// situation and throw an exception instead.
if (inCallback || inNewWindow) {
SWT.error(SWT.ERROR_FAILED_EVALUATE, null, " [WebView2: deadlock detected]");
}
}

At this specific point (handleCallJava), the deadlock check is missing. This is something we may fix.

@HeikoKlare HeikoKlare added Windows Happens on Windows OS edge Edge Browser labels Jul 26, 2024
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Aug 8, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Aug 8, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Aug 16, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Aug 22, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Aug 30, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 2, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 2, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 2, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 3, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 4, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 4, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 4, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 5, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 6, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 10, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 10, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 11, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 11, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 11, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 13, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 13, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 13, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 13, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 16, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 16, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 16, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 19, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 19, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 20, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 23, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 23, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 25, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 25, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
amartya4256 added a commit to amartya4256/eclipse.platform.swt that referenced this issue Sep 25, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
HeikoKlare pushed a commit that referenced this issue Sep 25, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to #669
@amartya4256
Copy link
Contributor

Fixed with #1378

@akurtakov
Copy link
Member

Fixed with #1378

Did you mean to close it with this comment ?

@sratz sratz closed this as completed Oct 7, 2024
@sratz sratz added this to the 4.34 M1 milestone Oct 7, 2024
lathapatil pushed a commit to swt-initiative31/prototype-gtk that referenced this issue Nov 14, 2024
This contribution fixes Edge browser Deadlock issue on instantiating a
new Edge Browser object during a webview callback using async execution.
The Implementation follows the pattern similar to how WebKit has been
implemented imitating the async behaviour in a sync fashion using
Futures and callbacks.

contributes to eclipse-platform#669
HeikoKlare pushed a commit to amartya4256/eclipse.platform.swt that referenced this issue Jan 27, 2025
This commit contributes to refactoring of all the ICoreWebView2*
instances into a wrapper class WebViewWrapper for better encapsulation
and fault proof initialization using a single future.

Contributes to
eclipse-platform#669
HeikoKlare pushed a commit to amartya4256/eclipse.platform.swt that referenced this issue Jan 27, 2025
This commit contributes to refactoring of all the ICoreWebView2*
instances into a wrapper class WebViewWrapper for better encapsulation
and fault proof initialization using a single future.

Contributes to
eclipse-platform#669
HeikoKlare pushed a commit to amartya4256/eclipse.platform.swt that referenced this issue Jan 27, 2025
This commit contributes to refactoring of all the ICoreWebView2*
instances into a wrapper class WebViewWrapper for better encapsulation
and fault proof initialization using a single future.

Contributes to
eclipse-platform#669
HeikoKlare pushed a commit to amartya4256/eclipse.platform.swt that referenced this issue Jan 27, 2025
This commit contributes to refactoring of all the ICoreWebView2*
instances into a wrapper class WebViewWrapper for better encapsulation
and fault proof initialization using a single future.

Contributes to
eclipse-platform#669
HeikoKlare pushed a commit to amartya4256/eclipse.platform.swt that referenced this issue Jan 27, 2025
This commit contributes to refactoring of all the ICoreWebView2*
instances into a wrapper class WebViewWrapper for better encapsulation
and fault proof initialization using a single future.

Contributes to
eclipse-platform#669
HeikoKlare pushed a commit to amartya4256/eclipse.platform.swt that referenced this issue Jan 27, 2025
This commit contributes to refactoring of all the ICoreWebView2*
instances into a wrapper class WebViewWrapper for better encapsulation
and fault proof initialization using a single future.

Contributes to
eclipse-platform#669
HeikoKlare pushed a commit that referenced this issue Jan 28, 2025
This commit contributes to refactoring of all the ICoreWebView2*
instances into a wrapper class WebViewWrapper for better encapsulation
and fault proof initialization using a single future.

Contributes to
#669
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
edge Edge Browser Windows Happens on Windows OS
Projects
None yet
Development

No branches or pull requests

5 participants