Bug 575248 - [win32] Out of handles if using EDGE browser
Summary: [win32] Out of handles if using EDGE browser
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.20   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks: 575660 573985
  Show dependency tree
 
Reported: 2021-08-04 20:44 EDT by Christopher Mindus CLA
Modified: 2023-10-23 08:16 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Mindus CLA 2021-08-04 20:44:24 EDT

    
Comment 1 Christopher Mindus CLA 2021-08-04 21:09:27 EDT
Using Windows 10 or 11, it should be known that the internal browser Microsoft Internet Explorer 11 is out of the game, the replacement being Microsoft Edge. But there are SERIOUS flaws in SWT and Window handles present.

Code not working:
  new Browser(parent,SWT.EDGE);

Code currently working:
  new Browser(parent,SWT.NONE):

Our product IIZI relies on the Browser component to work, in Windows using Explorer. However, switching to Edge (globally in out software) causes a problem with "SWT-out-of-handles" VERY quickly: we can open 2-3 of our Shell/Composite's in comparison to Explorer with over 200 open using the "old fashion". So there must be a severe leak somewhere of "Window Handles". It might be inside Eclipse Edge Browser component, but also likely to be in the product itself!

As Windows Explorer 11 is going away soon and being replaced by Edge, it is quite URGENT to fix this issue.

The typical stack trace of the exception with "No more handles" exists in so many reported cases, so there is no point in repeating it here.
Comment 2 Andrey Loskutov CLA 2021-08-05 02:01:01 EDT
(In reply to Christopher Mindus from comment #1) 
> The typical stack trace of the exception with "No more handles" exists in so
> many reported cases, so there is no point in repeating it here.

Please attach it here, unless you already know how to fix the issue. 

Please also provide minimal but complete steps to reproduce (ideally self contained SWT snippet or a project with description what need to be done to force the problem) along with the exact Eclipse version used.
Comment 3 Niraj Modi CLA 2021-08-05 02:08:39 EDT
Able to launch Edge92 on my Win10 machine.
So double check if you have the required Edge configuration on your machine.

Edge rendering back-end uses the WebView2 component, which is based on, but distinct from the Edge browser itself. WebView2 has to be installed separately from one of the following sources: 

Please have look at the detailed steps for how to use EDGE on SWT FAQ page:
https://www.eclipse.org/swt/faq.php#howuseedge
Comment 4 Christopher Mindus CLA 2021-08-10 07:55:12 EDT
(In reply to Niraj Modi from comment #3)
> Able to launch Edge92 on my Win10 machine.
> So double check if you have the required Edge configuration on your machine.
> 
> Edge rendering back-end uses the WebView2 component, which is based on, but
> distinct from the Edge browser itself. WebView2 has to be installed
> separately from one of the following sources: 
> 
> Please have look at the detailed steps for how to use EDGE on SWT FAQ page:
> https://www.eclipse.org/swt/faq.php#howuseedge

Well, this information is a little outdated. E.g.

>>> from https://www.eclipse.org/swt/faq.php#howuseedge:

WebView2 creates a user data directory to stores caches and persistent data like cookies and localStorage. All WebView2 instances in an application and all instances of the same application share this directory.

The default user directory location is %LOCALAPPDATA%\<AppName>\WebView2, where <AppName> is defined with Display.setAppName(). This location can be overridden on a per-process basis by setting the org.eclipse.swt.browser.EdgeDataDir Java property."
<<<

is clearly wrong, it is perhaps true for Edge88. It is also not specifying if you have created a "product" packaging, much like eclipse.exe itself.

But yes, I also get Edge92 Browser component created in Eclipse for Java 4.20 (2021-06), but sometimes the class BrowserFunction does not work at all (the JavaScript doesn't see the added function), the page must be reloaded in order to work. This is valid for both latest Windows 10 and Windows 11 developer previews.

Then I must ask you: how does Eclipse 4.20 internal browser instantiate its Edge browser component? Is it not using the SWT Browser component? If it is using the SWT Browser component, how come we have to install the WebView2 separately?

BTW: It's very difficult to create a test case with a simple SWT snippet because we don't really understand where the Edge Browser component fails! It is clear that BrowserFunction's sometimes does not work.

I have a pertinent question: how to clear the SWT Edge Browser image/data cache programmatically? It's been asked a lot on the internet, but no-one has the correct answer, at least for Edge92. Is there a way to do this using an SWT API, or could it be added? If files used for the browser are modified on the file system, they are not reloaded using the Edge Browser component. This is very noticeable when debugging our Eclipse-based product (not RCP) from Eclipse 4.20.
Comment 5 Christopher Mindus CLA 2021-08-10 08:02:35 EDT
Oh, yes: for the cache-clearing: we do this automatically when Internet Explorer is used, and our data/images are changed, prior to creating the Browser component. We would like to do the same for Edge Browser, but only the data/images, not browsing history, passwords, etc. It would be awesome to have an API support for it, or even do it using the OS class.

And I must say, even if one tries to be VERY careful with Window/GDI handles and have no handle leaks, we run out of them, even when the registry values are bumped up to almost maximum. Is there a counter somewhere that can be accessed? In this way we could prevent or warn the user to close open editors (reuse or close them programmatically).
Comment 6 Rainer Herter CLA 2022-03-03 03:20:13 EST
(In reply to Christopher Mindus from comment #4)
> But yes, I also get Edge92 Browser component created in Eclipse for Java
> 4.20 (2021-06), but sometimes the class BrowserFunction does not work at all
> (the JavaScript doesn't see the added function), the page must be reloaded
> in order to work. This is valid for both latest Windows 10 and Windows 11
> developer previews.

We have the same issue. For most users, the browser functions work fine, but for some reason there are just a few users having the same issue as described above: Browserfunctions only work after manual refresh. Very annoying.

Is there any progress on this?
Comment 7 Christoph Kaser CLA 2023-10-23 08:16:26 EDT
We have this issue as well: Occasionally, a browser with SWT.Edge triggers the following exception:

org.eclipse.swt.SWTError: No more handles [0x80070002]
	at org.eclipse.swt.SWT.error(SWT.java:4944)
	at org.eclipse.swt.browser.Edge.error(Edge.java:190)
	at org.eclipse.swt.browser.Edge.create(Edge.java:343)
	at org.eclipse.swt.browser.Browser.<init>(Browser.java:99)
	at de.iconparc.idt.browser.EdgeBrowserBridge.createBrowser(EdgeBrowserBridge.java:54)
	at [...]

Restarting eclipse solves the problem, until it occurs again.