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

Support Edge instances in different displays #1013 #1018

Conversation

HeikoKlare
Copy link
Contributor

The current implementation of the Edge browser creates a WebView2Environment on first creation of an WebView2 / Edge browser instance. On every further creation of a WebView2 instance, this environment is used. In case the WebView2 instance is created for a different display, i.e., within a different thread, the instantiation fails as the WebView2Environment has been created in a different thread.

To support the creation of WebView2 instances in different displays, this change replaces the static WebView2Environment with one environment for every display. The WebView2 instances are created for the environment belonging to the display for which the current instantiation is requested. An according regression test is added.

Contributes to #1013

A documentation for using multiple WebView2 environments can be found here: https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/process-model?tabs=csharp#multiple-environment-objects

@HeikoKlare HeikoKlare force-pushed the issue-1013-multiple-edge-environments branch from 329bae4 to 1ee38dd Compare January 31, 2024 11:08
Copy link
Contributor

github-actions bot commented Jan 31, 2024

Test Results

   299 files  ±0     299 suites  ±0   6m 28s ⏱️ -48s
 4 100 tests +1   4 092 ✅ +1   8 💤 ±0  0 ❌ ±0 
12 212 runs  +3  12 137 ✅ +1  75 💤 +2  0 ❌ ±0 

Results for commit 82d080b. ± Comparison against base commit 44432b2.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@vogella vogella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @HeikoKlare

I suggest to merge this also today, so that we have test all your fixes in tomorrows I-build

@HeikoKlare HeikoKlare force-pushed the issue-1013-multiple-edge-environments branch from 1ee38dd to 52a73be Compare January 31, 2024 14:12
@HeikoKlare
Copy link
Contributor Author

I suggest to merge this also today, so that we have test all your fixes in tomorrows I-build

Sure, just note that "test" precisely means "manual test" because there are currently only three tests executed against the Edge browser (since I did not manage to make #672 running successfully yet).
At least I applied the commit of #672 to this PR to execute all the browser tests against the Edge browser as well, and only test_setUrl_local() fails (but also does without this PR).

I made slight changes after your review, in 52a73be. They concern the following:

  • Store the environment an Edge instance belongs to within that instance, so that race conditions when accessing the global map on browser disposal are avoided
  • Use waitForPassCondition() in tests instead of doing busy waiting without a timeout
  • Dispose the additional displays in the test

There is one thing to consider left: the logic for clearing cookies (provided statically via Browser.clearSessions()) will clear the cookies of the environment for which the current thread is the UI thread. This is bit strange, as one might expect a static method to clear all cookies of all environments. And if you call the method on an object rather than the class, it is even more misleading as you might have browser1 and browser2 with different displays and call browser1.clearSessions() from the UI thread of browser2, resulting in the coockies of only browser2 to be cleared.
In my opinion, this is rather an existing API problem (clearSessions() being a static method), which we cannot fix easily. But I still wanted to point out that behavior.

The current implementation of the Edge browser creates a
WebView2Environment on first creation of an WebView2 / Edge browser
instance. On every further creation of a WebView2 instance, this
environment is used. In case the WebView2 instance is created for a
different display, i.e., within a different thread, the instantiation
fails as the WebView2Environment has been created in a different thread.

To support the creation of WebView2 instances in different displays,
this change replaces the static WebView2Environment with one environment
for every display. The WebView2 instances are created for the
environment belonging to the display for which the current instantiation
is requested. An according regression test is added.

Contributes to
eclipse-platform#1013
@HeikoKlare HeikoKlare force-pushed the issue-1013-multiple-edge-environments branch from 52a73be to 82d080b Compare January 31, 2024 14:35
@HeikoKlare HeikoKlare marked this pull request as ready for review January 31, 2024 17:02
@HeikoKlare HeikoKlare merged commit 3241d04 into eclipse-platform:master Jan 31, 2024
13 checks passed
@HeikoKlare HeikoKlare deleted the issue-1013-multiple-edge-environments branch January 31, 2024 17:03
@vogella
Copy link
Contributor

vogella commented Jan 31, 2024

Thank you @HeikoKlare Looking forward to test your changes tomorrow, but with the edge data dir set it is already very stable for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants