---
title: "Recipe: wait for a click in a partitioned frame"
description: "Wait in app.ts for a click inside a partitioned frame with @exact/browser-automation: arm a listener, click, then await it in one mutation."
modificationDate: "2026-11-24"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: wait for a click in a partitioned frame

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/wait-for-a-frame-click: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

In one mutation, arm the listener, click, then await its promise.

`bun exact.mjs add @exact/browser-automation`. In `app.ts`

```prompt Use this recipe in my app
Make the Exact app in this folder do what this recipe describes. Use https://github.com/expo/exact/blob/main/docs/recipes/wait-for-a-frame-click.md as the source for each step. The Exact checkout has the same page at docs/recipes/wait-for-a-frame-click.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. Read the recipe. If it leaves a choice that I did not make (which screen, which data, which platforms), propose one and ask me before you write code.
3. Do what the recipe says, in its order, with its tags, properties, functions and grants. Its component, state and URL names are examples. Change nothing else in the app.
4. Add a test in app.test.contract for each thing a person does that you changed. Copy the recipe's `contract-test` block where it has one. A drive operation the recipe shows (`call`, a ticket answer such as `tap @N accepted`) is not a test step: run it with `bun exact.mjs agent`.
5. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 6) and report it; do not keep trying.
6. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
7. Tell me what you changed, what the tests and checks reported, and what I must still do by hand.
```

```ts
import type { Answer, Sources } from './app.contract.d.ts';
import { addPreloadScript, evaluate } from '@exact/browser-automation';

export const grants = 'browser.automation';
const frame = { id: 'tab', sandbox: 'automation' };

const armClick = () => evaluate({ ...frame, expression: `(() => {
  const go = document.querySelector('#go');
  if (!go) throw Error('Missing #go');
  window.clicked = new Promise(resolve => {
    go.addEventListener('click', () => resolve('clicked'), { once: true });
  });
  return true;
})()` });

const click = () => evaluate({ ...frame, userActivation: true,
  expression: "document.querySelector('#go').click()" });

async function waitForClick() {
  const { result } = await evaluate({ ...frame, expression: 'window.clicked', awaitPromise: true });
  if (String(result) !== 'clicked') throw Error('No click');
  return { text: 'clicked' };
}

const sources: Sources = {
  setup: () => addPreloadScript({ ...frame, functionDeclaration: '() => {}' }).then(() => ({})),
  runPair: async () => {
    await armClick();
    await click();
    return waitForClick();
  },
};
export const answer: Answer = (source, args, store, storage, native) =>
  sources[source](args, store, storage, native);
```

Check `exactPage().iframePartition`. Use your URLs and a unique id. Match `e.url`
after redirects. On Android, navigate after registration. Without isolated
worlds, expect `NotSupportedError`.
Keep the document and enabled `<button type="button" id="go">` mounted. Rearm per click or navigation.

```contract
shape Done

shape Heard
  text: string

component Tab
  state err = ""
  mutation ready as shape Done then openPage
  mutation heard as shape Heard
  action failed(e: FrameNavigation)
    err = e.message
  action loaded(e: FrameNavigation)
    err = ""
    if ready == none
      if not pending(ready)
        send ready = setup()
    else if e.url == "https://a.test/form"
      send heard = runPair()
  action openPage
    navigate("tab", "https://a.test/form")
  view
    column
      iframe id="tab" src="https://a.test/" partition="persist:browser" navigatesuccess=loaded navigateerror=failed
      text err
      for item, i in [failure(ready), failure(heard)] key=i
        text (match item { case some(f) => f.message, case none => "" })
      text (match heard { case some(r) => r.text, case none => "" })
```

For an external click replace `runPair` with

```text
arm: async () => { await armClick(); return {}; },
waitForClick,
press: async () => { await click(); return {}; },
```

In `loaded` send `armed = arm()` at the form. Once armed, either send can run first.
Show `armed` and `acted` failures. For a manual click omit `press`,
`acted` and its send.

```text
  mutation armed as shape Done then listen
  mutation acted as shape Done
  action listen
    send heard = waitForClick()
    send acted = press()
```
