Browser Extensions for AI Chat: Adding Memory, Tools, and Scheduled Tasks
Learn how browser extensions can add persistent memory, tool execution, and scheduled tasks to web-based AI chat. This practical guide covers implementation patterns, function-calling requirements, Manifest V3 scheduling limits, and the privacy and permission checks these capabilities require.
1. Three Limitations of Web-Based AI Chat
A web chat interface is an easy way to start using a large language model. For regular users, however, three limitations stand out:
- No cross-session memory. Each new conversation starts without your preferences, business context, or preferred output formats. Repeatedly asking for tables or a three-part structure adds up to a substantial communication overhead.
- It can talk, but it cannot act. The model reasons over the text you provide, without independently retrieving current information or reading and writing local files.
- No scheduled execution. Recurring work, such as daily industry briefings or weekly data summaries, still requires someone to start the conversation manually.
These limitations share a common cause: the model is confined to a request-and-response interface. A browser extension runs in your browser and can access pages, make requests, and use local storage. Without modifying the model service itself, it can provide these three capabilities around it.
Before building, check an important prerequisite: what an extension can do depends on whether the model service supports function calling and whether its API and page structure remain stable. Web-based services often lack public extension interfaces. Page redesigns or changes to the service’s terms may break the approach. Confirm that the terms of service permit your intended use.
2. Implementing the Three Capabilities
Persistent Memory
Persistent memory separates preferences and background information from individual conversations, stores them locally, and injects them into the context before each request.
// Save a memory entryawait chrome.storage.local.set({memories: [{id: "m-001",type: "preference", // preference | fact | workflowcontent: "Prefer Markdown for table output",confidence: 0.9,createdAt: Date.now(),lastUsedAt: Date.now()}]});
Memory should not grow indefinitely. Before injecting entries, score them by recency, confidence, and relevance to the current question. Select only the highest-ranking entries and enforce a total length limit—for example, 1,500 tokens.
Merge duplicate entries. Sensitive information, including government identification numbers, phone numbers, and account details, should not be stored as memory or injected into requests.
Tool Calling
To let a model take action, implement a client-side function-calling loop:
- The extension defines local tools, such as fetching text from a specified web page, reading the current tab, or parsing Word and Excel files.
- Each tool’s name, purpose, and parameters are described using JSON Schema and sent with the model request.
- The model chooses a tool to call. The extension executes it locally and returns the result as a new message.
- The loop continues until the model produces a final response.
Here is an example tool definition:
{"name": "fetch_page","description": "Fetch the main text of a specified public web page","parameters": {"type": "object","properties": {"url": { "type": "string", "format": "uri" }},"required": ["url"],"additionalProperties": false}}
The loop needs explicit limits. At a minimum, consider:
- Maximum rounds: For example, stop after eight rounds and explain why execution ended.
- Per-call timeout: For example, allow 30 seconds for a tool call.
- Failure retries: Retry no more than twice, with progressively longer delays.
- Tool output limits: For example, retain no more than 4,000 characters to avoid overwhelming the context window.
There are also implementation prerequisites. The model or API must support function calling. The extension must protect authentication credentials and account for request rewriting, cross-origin resource sharing (CORS), and content security policy (CSP) restrictions.
Changes to page structure can break tools that extract page content. Every tool should return error information so the model can identify which step failed.
Local tool execution does not mean the data stays on the device. With a cloud-hosted model, injected memories, retrieved page content, and file excerpts are sent to the model provider as context. Only when the model also runs locally can this workflow keep data entirely on the device. Make that distinction clear in the design and in the user interface.
Scheduled Tasks
Scheduled tasks turn an assistant from a reactive chat interface into a system that delivers results proactively. For example:
# Run every day at 8:00 a.m.cron: "0 8 * * *"prompt: "Find and summarize yesterday's industry news in ten bullet points"session: task-daily-news # Separate session to prevent context mixing
Several implementation details matter.
Under Manifest V3, the browser can terminate an idle background service worker, so a regular setInterval is unreliable. Use chrome.alarms to register scheduled events that wake the service worker.
chrome.alarms does not directly support cron expressions. Parse the expression yourself, calculate the next execution time, and register it using the when parameter. After each task finishes, calculate and register the next run.
Scheduling also depends on the browser being open. When the browser is closed, an extension cannot trigger tasks. System notifications are only an output channel; they cannot replace a scheduler.
If a task must run at a specific time, provide an additional fallback. Options include connecting to a persistent local component through nativeMessaging, or using an operating system scheduler such as launchd or Task Scheduler to launch the browser at the required time.
After the browser restarts, check for missed tasks and decide whether to run or skip them.
3. Privacy and Security
Storing memories, keys, and task outputs locally is an advantage of this approach. It also shifts more security responsibility to the user.
API Key Management
Keep API keys only in chrome.storage.local and send them only to the selected model provider when making model requests—not to other third parties.
Do not put keys in source code, logs, or exported configuration files. Rotate them regularly and revoke them immediately if you notice unexpected usage.
Permission Review Checklist
Before installing an extension, review each permission it requests.
| Permission | Purpose | What to check |
|---|---|---|
host_permissions |
Access specified websites | Restrict access to the model service’s domains and domains required for fetching content. Avoid <all_urls>. |
storage |
Store memories and settings | Appropriate for this purpose, but verify that the data is not synchronized to a remote service. |
alarms |
Schedule tasks | Appropriate for scheduled execution. |
notifications |
Notify users of task results | Use only to display notifications, not as a scheduling mechanism. |
scripting, activeTab |
Read content from the current page | — |
