Bug 574627

Summary: [Win32][Edge] Failed to evaluate javascript expression [WebView2: deadlock detected]
Product: [Eclipse Project] Platform Reporter: Serhiy Davydiuk <s.davyduik>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: NEW --- QA Contact:
Severity: major    
Priority: P3 CC: kelly, nikita, niraj.modi, OSKozlov
Version: 4.21   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
Whiteboard:
Bug Depends on:    
Bug Blocks: 575660, 573985    
Attachments:
Description Flags
Example none

Description Serhiy Davydiuk CLA 2021-07-02 13:46:02 EDT
Win10
-Dorg.eclipse.swt.browser.DefaultType=edge
Microsoft.WebView2.FixedVersionRuntime.90.0.818.66.x64
SWT v4946r10

Click on the link and error occurs. Apllication crashes.

Example code:

package aTests;

import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class WebView2DeadLock {
	public static void main(String [] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		shell.setText("WebView2DeadLock");
		final Browser browser = new Browser(shell, SWT.EDGE);

		shell.open();
		browser.setText("<!DOCTYPE html><html><body>"
				+ "<p>Click the button to open a new browser window.</p>"
				+ "<a href=\"http://eclipse.org\">Try it</a>"
				+ "</body></html>");
		browser.addLocationListener(LocationListener.changingAdapter(e -> {
			if (!e.location.contains("eclipse.org")) return;

			Shell sh = new Shell(e.display);
            sh.setLayout(new FillLayout());
            Browser br = new Browser(sh, SWT.NONE);
            try {
                br.setUrl(new URL(e.location).toExternalForm());
            } catch (MalformedURLException ex) {
            }
		}));
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
}

Exception:
Exception in thread "main" org.eclipse.swt.SWTException: Failed to evaluate javascript expression [WebView2: deadlock detected]
	at org.eclipse.swt.SWT.error(SWT.java:4893)
	at org.eclipse.swt.browser.Edge.checkDeadlock(Edge.java:147)
	at org.eclipse.swt.browser.Edge.create(Edge.java:210)
	at org.eclipse.swt.browser.Browser.<init>(Browser.java:99)
	at aTests.WebView2DeadLock.lambda$0(WebView2DeadLock.java:31)
	at org.eclipse.swt.browser.LocationListener$1.changing(LocationListener.java:81)
	at org.eclipse.swt.browser.Edge.handleNavigationStarting(Edge.java:446)
	at org.eclipse.swt.browser.Edge.handleNavigationStarting(Edge.java:428)
	at org.eclipse.swt.browser.Edge.lambda$0(Edge.java:87)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(Native Method)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3624)
	at aTests.WebView2DeadLock.main(WebView2DeadLock.java:38)
Comment 1 Serhiy Davydiuk CLA 2021-07-02 14:05:16 EDT
Please check fixed code in attachments
Comment 2 Serhiy Davydiuk CLA 2021-07-02 14:06:00 EDT
Created attachment 286719 [details]
Example
Comment 3 Serhiy Davydiuk CLA 2024-01-22 16:51:29 EST
Not reproducible using WebView 120.0.2210.144, can be closed
Comment 4 Serhiy Davydiuk CLA 2024-01-22 16:58:51 EST
My bad, still reproducible with example (eclipse platform 4-27, WebView2 120.0.2210.144)

public class WebView2DeadLock {
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		shell.setText("WebView2DeadLock");
		final Browser browser = new Browser(shell, SWT.EDGE);

		shell.open();
		browser.setText("<!DOCTYPE html><html><body>"
				+ "<p>Click the button to open a new browser window.</p>"
				+ "<a href=\"http://eclipse.org\">Try it</a>"
				+ "</body></html>");
		browser.addLocationListener(LocationListener.changingAdapter(e -> {
			if (!e.location.contains("eclipse.org"))
				return;

			Shell sh = new Shell(e.display);
			sh.setLayout(new FillLayout());
			Browser br = new Browser(sh, SWT.EDGE);
			try {
				br.setUrl(new URL(e.location).toExternalForm());
			} catch (MalformedURLException ex) {
			}
			e.doit = false;
		}));
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}