Prompt API - Instructions
This page is a simple example of the browser Prompt API.
The page checks whether the API is available, enables the Perform Prompt button when it can be used, sends the context and prompt to the browser model, and displays the generated response.
Functionality
The Prompt API page has:
- A textarea for system-style context.
- A textarea for the user prompt.
- A
Perform Promptbutton that is disabled when the API is not available. - An availability message showing the browser API state.
- A progress indicator for session creation, model download, and prompting.
- A prompt results area.
The JavaScript for the page is in /js/pages/browser-ai-prompt.js so it can be inspected and debugged in browser developer tools.
Testing To Consider
Test the availability flow in browsers with and without Prompt API support.
Check that the button starts disabled, becomes enabled only when the API is usable, and remains disabled when the API is unavailable or the availability check fails.
Try an empty prompt, short prompts, longer prompts, and context that changes the expected style or scope of the answer. Responses are generated by an AI model, so exact wording should not be treated as deterministic.
Observe the progress indicator during model download and prompting. The first run may take longer because the model may need to download.
Check error handling by using unsupported browsers, blocked permissions, or test environments where the API exists but cannot create a language model session.
For automation, assert on stable UI state transitions and the presence of a non-empty result rather than exact AI-generated text.
Nuances
- Are the outputs consistently repeatable?
- What happens with cross browser compatibility? This is a Chrome API.
- What about different machine capabilities - this is AI running in a local browser.