Skip to content

Add timer to demonstrate new AbortSignal introduce in Chrome 153 - #403

Draft
marcianoskate wants to merge 7 commits into
mainfrom
feat/abort-timer
Draft

Add timer to demonstrate new AbortSignal introduce in Chrome 153#403
marcianoskate wants to merge 7 commits into
mainfrom
feat/abort-timer

Conversation

@marcianoskate

Copy link
Copy Markdown
Collaborator

In the upcoming Chrome 153, a change to the API introduces the ability to pass an AbortSignal to the tool registration and tool execution. This enables long-running tasks to be properly notified when the user or the agent interrupts the task.

Comment thread demos/abort-timer/README.md Outdated
1. **Tool Registration Lifecycle:**
```javascript
const regController = new AbortController();
document.modelContext.registerTool(toolDefinition, { signal: regController.signal });

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ModelContextRegisterToolOptions signal has been available since Chrome 148.0.7757.0. This is not new.

Comment thread demos/abort-timer/README.md Outdated
const regController = new AbortController();
document.modelContext.registerTool(toolDefinition, { signal: regController.signal });
```
Calling `regController.abort()` unregisters the tool from the page's tool catalog, **without terminating or breaking in-flight tool executions**.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specific line is the new part in Chrome 153 though

Comment thread demos/abort-timer/README.md Outdated
const execController = new AbortController();
const promise = document.modelContext.executeTool(tool, args, { signal: execController.signal });
```
Passing `{ signal }` in `executeTool` provides that signal directly to the tool's `execute(params, clientContext)` callback. Calling `execController.abort()` immediately signals the running loop, freeing the event loop and settling the promise cleanly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clientContext isn't the right name. it's just options.

Comment thread demos/abort-timer/README.md Outdated

```javascript
// 1. Resolve modelContext with hybrid fallback
const modelContext = document.modelContext || navigator.modelContext || document.modelContextTesting;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only use document.modelContext now

Carlos Giraldo added 6 commits September 3, 2026 15:23
…and abort bugs

- Simplify DOM structure and eliminate Tailwind class injection in JS by using declarative data-state styling
- Extract pure zero-DOM startTimerExecution engine with AbortSignal listeners
- Add hard cancellation handle (bindCancel) and run sequence tracking (runId) to fix reset timer continuation bug
- Fall back to host AbortController signal when clientContext.signal is omitted by native Chrome WebMCP
- Add direct abort handle (bindAbort) and recover from Blink AbortError promise rejections
- Prevent duplicate execution loops by guarding on running/runaway states

TAG=agy
CONV=685fb023-d315-42af-be2f-2c2bc1ec0588
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants