2424using System . Collections . Concurrent ;
2525using System . Collections . Generic ;
2626using System . Threading . Tasks ;
27- using Microsoft . Extensions . Options ;
2827using WebDriverBiDi . BrowsingContext ;
2928using WebDriverBiDi . Input ;
3029
@@ -64,6 +63,8 @@ private BrowsingContext(UserContext userContext, BrowsingContext parent, string
6463
6564 public event EventHandler HistoryUpdated ;
6665
66+ public event EventHandler < UserPromptEventArgs > UserPrompt ;
67+
6768 public UserContext UserContext { get ; }
6869
6970 public string Id { get ; }
@@ -174,7 +175,7 @@ internal WindowRealm CreateWindowRealm(string sandbox = null)
174175 {
175176 var realm = WindowRealm . From ( this , sandbox ) ;
176177
177- realm . Worker += ( sender , args ) =>
178+ realm . Worker += ( _ , args ) =>
178179 {
179180 OnWorker ( args . Realm ) ;
180181 } ;
@@ -192,7 +193,7 @@ internal async Task ReloadAsync()
192193
193194 private void Initialize ( )
194195 {
195- UserContext . Closed += ( sender , args ) => Dispose ( "User context was closed" ) ;
196+ UserContext . Closed += ( _ , _ ) => Dispose ( "User context was closed" ) ;
196197
197198 Session . BrowsingContextContextCreated += ( sender , args ) =>
198199 {
@@ -205,15 +206,15 @@ private void Initialize()
205206
206207 _children . TryAdd ( args . UserContextId , browsingContext ) ;
207208
208- browsingContext . Closed += ( sender , args ) =>
209+ browsingContext . Closed += ( _ , _ ) =>
209210 {
210211 _children . TryRemove ( browsingContext . Id , out _ ) ;
211212 } ;
212213
213214 OnBrowsingContextCreated ( new BidiBrowsingContextEventArgs ( browsingContext ) ) ;
214215 } ;
215216
216- Session . BrowsingContextContextDestroyed += ( sender , args ) =>
217+ Session . BrowsingContextContextDestroyed += ( _ , args ) =>
217218 {
218219 if ( args . UserContextId != Id )
219220 {
@@ -223,7 +224,7 @@ private void Initialize()
223224 Dispose ( "Browsing context already closed." ) ;
224225 } ;
225226
226- Session . BrowsingContextDomContentLoaded += ( sender , args ) =>
227+ Session . BrowsingContextDomContentLoaded += ( _ , args ) =>
227228 {
228229 if ( args . BrowsingContextId != Id )
229230 {
@@ -234,7 +235,7 @@ private void Initialize()
234235 OnDomContentLoaded ( ) ;
235236 } ;
236237
237- Session . BrowsingContextLoad += ( sender , args ) =>
238+ Session . BrowsingContextLoad += ( _ , args ) =>
238239 {
239240 if ( args . BrowsingContextId != Id )
240241 {
@@ -274,7 +275,7 @@ private void Initialize()
274275 OnNavigation ( new BrowserContextNavigationEventArgs ( _navigation ) ) ;
275276 } ;
276277
277- Session . BrowsingContextHistoryUpdated += ( sender , args ) =>
278+ Session . BrowsingContextHistoryUpdated += ( _ , args ) =>
278279 {
279280 if ( args . BrowsingContextId != Id )
280281 {
@@ -284,7 +285,7 @@ private void Initialize()
284285 OnHistoryUpdated ( ) ;
285286 } ;
286287
287- Session . NetworkBeforeRequestSent += ( sender , args ) =>
288+ Session . NetworkBeforeRequestSent += ( _ , args ) =>
288289 {
289290 if ( args . BrowsingContextId != Id )
290291 {
@@ -300,6 +301,17 @@ private void Initialize()
300301 _requests . TryAdd ( args . Request . RequestId , request ) ;
301302 Request ? . Invoke ( this , new RequestEventArgs ( request ) ) ;
302303 } ;
304+
305+ Session . BrowsingContextUserPromptOpened += ( _ , args ) =>
306+ {
307+ if ( args . BrowsingContextId != Id )
308+ {
309+ return ;
310+ }
311+
312+ var userPrompt = Core . UserPrompt . From ( this , args ) ;
313+ OnUserPromptOpened ( new UserPromptEventArgs ( userPrompt ) ) ;
314+ } ;
303315 }
304316
305317 private void OnNavigation ( BrowserContextNavigationEventArgs args ) => Navigation ? . Invoke ( this , args ) ;
@@ -324,4 +336,6 @@ private void Dispose(string reason)
324336 private void OnClosed ( string reason ) => Closed ? . Invoke ( this , new ClosedEventArgs ( reason ) ) ;
325337
326338 private void OnWorker ( DedicatedWorkerRealm args ) => Worker ? . Invoke ( this , new WorkerRealmEventArgs ( args ) ) ;
339+
340+ private void OnUserPromptOpened ( UserPromptEventArgs args ) => UserPrompt ? . Invoke ( this , args ) ;
327341}
0 commit comments