API ReferenceJavaHooks
Hooks
A hook coordinates a browser-native event that fires asynchronously outside any direct call — a new tab, a native file picker, a download. registerHook before the triggering action, then waitFor it, so the event can't be missed between the two.
Hooks.NEW_PAGE
Waits for a tab opened by the triggering action. Registers on the page that triggers the event (not the browser) as of v0.1.6, which fixed misattribution when more than one tab could plausibly open around the same time.
public static final HookType<Page> NEW_PAGEExample
Hook<Page> hook = page.registerHook(Hooks.NEW_PAGE);
page.click("a[target=_blank]");
Page newPage = hook.waitFor();Hooks.FILE_CHOOSER
Waits for the native file-picker dialog; no OS dialog actually renders. The resulting FileChooser's setFiles(...) supplies one or more paths.
public static final HookType<FileChooser> FILE_CHOOSERExample
Hook<FileChooser> hook = page.registerHook(Hooks.FILE_CHOOSER);
page.click("button.open-upload");
FileChooser chooser = hook.waitFor();
chooser.setFiles(Path.of("fixtures/document.pdf"));Hooks.DOWNLOAD
Resolves as soon as a download starts, exposing url() and suggestedFilename() immediately. The resulting Download's saveAs(...) waits for it to finish and copies it to path.
public static final HookType<Download> DOWNLOADExample
Hook<Download> hook = page.registerHook(Hooks.DOWNLOAD);
page.click("a.download-report");
Download download = hook.waitFor();
download.saveAs(Path.of("artifacts", download.suggestedFilename()));