allwright

API ReferenceTypeScriptHooks

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 wait for it, so the event can't be missed between the two.

hooks.newPage

PropertySince v0.1.5

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.

hooks.newPage: HookType<Page>

Example

import { hooks } from "@allwright.dev/core";
const hook = await page.registerHook(hooks.newPage);
await page.click("a[target=_blank]");
const newPage = await hook.wait();

hooks.fileChooser

PropertySince v0.1.7

Waits for the native file-picker dialog; no OS dialog actually renders. The resulting FileChooser's setFiles(...) supplies one or more paths.

hooks.fileChooser: HookType<FileChooser>

Example

const hook = await page.registerHook(hooks.fileChooser);
await page.click("#file-upload-input");
const chooser = await hook.wait();
await chooser.setFiles("README.md");

hooks.download

PropertySince v0.1.7

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.

hooks.download: HookType<Download>

Example

const hook = await page.registerHook(hooks.download);
await page.click('[download="README.md"]');
const download = await hook.wait();
await download.saveAs("README1.md");