Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit cbeaa81

Browse files
committed
Add handler on dialog box open
This handler will listen out for when dialog boxes are opened. When a CDP event is received for a dialog box opening, we will automatically dismiss it. This is the first step in dealing with dialog boxes.
1 parent d450671 commit cbeaa81

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

common/frame_session.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,25 @@ func (fs *FrameSession) initEvents() {
259259
fs.onAttachedToTarget(ev)
260260
case *target.EventDetachedFromTarget:
261261
fs.onDetachedFromTarget(ev)
262+
case *cdppage.EventJavascriptDialogOpening:
263+
fs.onEventJavascriptDialogOpening(ev)
262264
}
263265
}
264266
}
265267
}()
266268
}
267269

270+
func (fs *FrameSession) onEventJavascriptDialogOpening(event *cdppage.EventJavascriptDialogOpening) {
271+
fs.logger.Debugf("FrameSession:onEventJavascriptDialogOpening",
272+
"sid:%v tid:%v url:%v dialogType:%s",
273+
fs.session.ID(), fs.targetID, event.URL, event.Type)
274+
275+
action := cdppage.HandleJavaScriptDialog(false)
276+
if err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {
277+
fs.logger.Errorf("FrameSession:onEventJavascriptDialogOpening", "failed to dismiss dialog box: %v", err)
278+
}
279+
}
280+
268281
func (fs *FrameSession) initFrameTree() error {
269282
fs.logger.Debugf("NewFrameSession:initFrameTree",
270283
"sid:%v tid:%v", fs.session.ID(), fs.targetID)

0 commit comments

Comments
 (0)