Documentation
¶
Overview ¶
Command dialogs is a chromedp example demonstrating how to handle the JavaScript dialogs of a page. It loads a local page with a button for each kind of dialog: alert, confirm, prompt and beforeunload. A goroutine listens for the event Page.javascriptDialogOpening and answers each dialog with the command Page.handleJavaScriptDialog. It accepts an alert, dismisses a confirm, accepts a prompt with a text, and accepts the dialog that asks whether the page can unload. The program prints the message and the answer of each dialog, and the text that the page shows after it. A dialog blocks the page, and so it blocks the click that opens it. The goroutine must answer while the click waits. It starts a local server and needs no internet. Use -v to print the protocol messages and -visible to show the browser window and leave it open. Use -visible-on-terminal to draw the page in the terminal with terminal graphics.