allwright

API ReferenceGoHooks

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.

allwright.Hooks.NewPage // HookType[*Page]

Example

hook, _ := allwright.RegisterHook(ctx, page, allwright.Hooks.NewPage)
page.Click(ctx, "a[target=_blank]")
newPage, _ := hook.Wait(ctx)

Hooks.FileChooser

PropertySince v0.1.7

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

allwright.Hooks.FileChooser // HookType[*FileChooser]

Example

hook, _ := allwright.RegisterHook(ctx, page, allwright.Hooks.FileChooser)
page.Click(ctx, "#upload")
chooser, _ := hook.Wait(ctx)
chooser.SetFiles(ctx, []string{"photo.png"})

Hooks.Download

PropertySince v0.1.7

Resolves as soon as a download starts, exposing URL() and SuggestedFilename() immediately. The resulting *Download's SaveAs(ctx, path) waits for it to finish and copies it to path.

allwright.Hooks.Download // HookType[*Download]

Example

hook, _ := allwright.RegisterHook(ctx, page, allwright.Hooks.Download)
page.Click(ctx, "a.download-report")
download, _ := hook.Wait(ctx)
download.SaveAs(ctx, "report.csv")