Browser Agents with LLMs: Architecture, Use Cases, and Security Practices

    This article examines how large language models can operate within browser extensions, covering persistent sidebar architectures, multi-tab collaboration, dynamic code generation, common enterprise use cases, and key security risks such as prompt injection and sensitive data leakage. It also outlines defense-in-depth practices including site-level permissions, human confirmation for high-risk actions, and sandboxed execution.

    As large language model (LLM) technology continues to evolve, its capabilities have expanded from text generation to actively operating computer environments. The browser, as the most frequently used terminal application in modern human-computer interaction, has naturally become a primary entry point for LLMs to demonstrate “computer use” capabilities. This article explores the agentic operation architecture of LLMs in browser extension form, core functional practices, and the security challenges and protection approaches they face.

    1. Core Architecture and Functions of Browser Agents

    Integrating LLMs into browser extensions so they can view and operate web pages is a major upgrade over traditional browser automation. Compared with early native desktop control approaches that were slow to respond and prone to failure, modern browser AI agents typically use a persistent sidebar architecture and interact continuously with LLMs through browser extension APIs.

    1.1 Persistent Sidebar and Multi-Tab Collaboration

    Modern AI browser extensions commonly adopt a sidebar design. This not only improves the immersive user experience but also provides an architectural foundation for parallel operations across multiple tabs. In this architecture, the LLM can parse the DOM structure of the current page through injected content scripts and extract key text and element nodes.

    Cross-tab collaboration is a core highlight of such applications. Users can instruct the AI to extract specific data from Tab A and process it in Tab B. The underlying implementation relies on the extension’s Background Service Worker for state management and message relay. For example:

    1. // Pseudocode: cross-tab communication and data processing
    2. chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
    3. if (request.action === 'fetchAndProcessData') {
    4. chrome.tabs.sendMessage(request.sourceTabId, {action: 'extractData'}, (response) => {
    5. // Pass the extracted data to the LLM for processing, then send it to the target tab
    6. processWithLLM(response.data).then(processedData => {
    7. chrome.tabs.sendMessage(request.targetTabId, {action: 'fillForm', data: processedData});
    8. });
    9. });
    10. }
    11. });

    1.2 Dynamic Code Generation and Execution

    To meet advanced developer needs, some high-end extensions introduce the ability to write, run, and test front-end code directly in the browser. Based on natural language instructions from users, the LLM can dynamically generate JavaScript snippets and execute them in the current page context through a sandbox mechanism. This capability greatly shortens the feedback loop from code ideation to result validation and makes rapid prototyping of front-end logic possible.

    2. Typical Application Scenarios and Enterprise Practices

    Browser AI agent scenarios cover multiple areas of daily office work and enterprise R&D:

    1. Information extraction and rewriting: For long technical documents or news pages, the AI can automatically scroll through and parse the full text, generate structured summaries, or perform multilingual translation.
    2. Form automation: In data entry scenarios for internal enterprise systems, the AI can identify page form structures and automatically fill them based on context or information extracted across pages, reducing repetitive manual work.
    3. R&D-assisted testing: Developers can have the AI automatically traverse page elements, generate test cases, and even perform interface interactions such as clicking buttons or expanding collapsed panels to verify the correctness of front-end interaction logic. If integrated with Baidu AI Cloud’s logging and monitoring and alerting services, teams can comprehensively record AI test execution paths and track anomalies.

    3. Security Challenges and Risk Analysis

    Although browser AI agents show strong automation potential, their direct access to users’ high-value data and operation permissions also sharply increases security risk.

    3.1 Prompt Injection Attacks

    Prompt injection is one of the most serious threats facing AI agents today. When an LLM is authorized to parse web page content, a malicious page may embed carefully constructed hidden instructions in its HTML text. For example, through invisible CSS styles or forged system prompts, an attacker can induce the LLM to send sensitive information on the page, such as locally stored tokens or user privacy data, to an external endpoint controlled by the attacker. Because LLMs have difficulty strictly distinguishing “system instructions” from “user data” at the instruction level, such attacks are often highly covert.

    3.2 Sensitive Data Leakage Vulnerabilities

    Security research organizations have disclosed data leakage vulnerabilities in multiple AI browser products. These vulnerabilities typically exploit the AI agent’s excessive trust in page elements and induce the model to execute specific DOM queries or code scripts to extract and send out sensitive context data from the user’s current session. More seriously, when some products attempt to fix such vulnerabilities, the patches are often bypassed again in subsequent adversarial testing because of a lack of global control over LLM behavior patterns.

    4. Designing Multi-Layer Security Protection Mechanisms

    Facing complex security challenges, building browser AI agents requires adopting the principle of defense in depth from the beginning of architectural design.

    4.1 Site-Level Permission Control

    The system should implement a strict domain-based permission allowlist strategy. Users can configure which websites allow the AI to read content and which websites allow the AI to perform clicks or form submissions. For high-risk sites such as financial systems and internal enterprise management systems, the AI’s write permissions should be disabled by default, with only read-only summarization capabilities retained.

    4.2 Human Confirmation for High-Risk Actions

    For any action that may cause a state change, such as submitting a form, executing a payment, or modifying account information, the system must adopt a “Human-in-the-loop” mechanism. After generating an execution plan, the LLM should first show the user the specific actions and target elements to be executed in a non-destructive way. The browser API can be called only after the user explicitly confirms.

    4.3 Context Isolation and Sandboxed Execution

    When executing JavaScript code dynamically generated by the AI, it must run in an isolated sandbox environment that restricts access to global properties of the window object and cross-origin APIs. At the same time, all abnormal network requests initiated by the AI should be intercepted to prevent sensitive data from leaking through covert channels. By combining Baidu AI Cloud container platform and security protection solutions, enterprises can perform fine-grained network traffic auditing and blocking for AI agent behavior in the cloud.

    5. Conclusion and Outlook

    The agentic operation capabilities of large language models in browser environments are reshaping the paradigm of human-computer interaction. From multi-tab collaboration to dynamic code execution, they bring unprecedented efficiency improvements to developers and enterprise users. However, security risks such as prompt injection and data leakage cannot be ignored. In the future, only through stricter permission control, more robust sandbox isolation, and multi-layer protection combined with cloud-native security solutions can AI browser agents truly unleash their enormous application value under safe and controllable conditions.