进阶 zcode.z.ai 2026-11-25 14:51:22 · 0 阅读

第22章 Browser Automation

Core FeaturesBrowser Automation The built-in browser in ZCode supports local development servers and online pages. With browser control enabled, the agent can navigate pages, click elements, complete forms, scroll, capture screenshots, record actions, and adjust the viewport. Subsequent actions are based on the current page state. Describe the required actions in natural language without writing browser scripts or element selectors. In the example below, the agent looks up venue information, plans a weekend itinerary, and opens a booking page to fill in and verify the form. The browser panel is desktop-only. Quick Start 1. Enable Built-in Browser Control Browser automation is provided by the official Browser Use plugin. In an open workspace, use Settings → Browser Use → Enable built-in browser control to view or change its status. This setting applies only to new sessions; create a new task after changing it. If the switch is unavailable, open or create a workspace first. The Security section on the same page provides an Ignore certificate errors switch. When enabled, the built-in browser skips HTTPS certificate validation. The setting affects only the built-in browser and requires a ZCode restart. The plugin also includes skills for browser operation and web interface inspection, which can be invoked as required. 2. Describe the Required Actions Specify the target page, required actions, and expected result in the task input. For example: Open http://localhost:5173/orders, set the filter to "Completed", check whether the list contains any records, and save a screenshot. 3. Monitor Browser Actions When the agent creates a tab, the browser panel expands and displays the corresponding page. Actions and page updates are visible in real time, and the agent verifies results against the updated page state. Example: Information Lookup and Form Completion This example uses a Beijing weekend itinerary to demonstrate venue research, route planning, form completion, and result verification on a demo booking page. Check the opening hours and booking requirements on the official websites of the Palace Museum, Jingshan Park, and UCCA. Plan a relaxed two-day itinerary for October 17–18 with a focus on architecture, exhibitions, and coffee. Complete the Beijing weekend demo booking form, review the information, and submit. Information lookup. Check the venues' official websites for opening hours, closing days, and booking requirements. Information that is unavailable or cannot be confirmed remains marked for verification. Form completion. Select the dates, group size, and interests according to the itinerary. In this example, the page shows that the 14:00 photo-walk slot is full, so the agent selects the available 16:00 slot. Result verification. Review the form summary before submission. After submission, check the generated itinerary card to confirm that the dates, group size, and time slot meet the requirements. This example uses a demo booking page with illustrative availability and submission results. Actual visits to the Palace Museum and similar venues require real-name booking through official channels. Example: Webpage Changes and Verification Browser automation can verify page layouts and interactions after code changes. The following travel demo illustrates route card updates, favorite controls, and narrow-screen layout verification. Update the route cards to use large landscape photos and add a favorite control to each route. Preserve favorite selections after a refresh. After the update, use the built-in browser to check desktop and mobile layouts, verify category filtering and favorite toggles, and resolve any issues before repeating the checks. After updating the code, the agent verifies category filtering, favorite toggles, and persistence after a refresh through page interaction. Layouts are checked at desktop (1280×800) and mobile (390×844) viewport sizes: The mobile check identifies horizontal overflow because the original multi-column layout is not adapted to narrow screens. A single-column layout makes the photos, route details, and favorite controls fully visible. The updated layout is then verified in both languages. Before: cards overflow the screenAfter: single-column layout with favorites Common Use Cases Common use cases and example instructions are listed below: ScenarioExample InstructionVerify page changesOpen http://localhost:5173/settings, switch to dark mode, and check text contrast against the backgroundVerify a form workflowComplete and submit the registration form with test data, recording each step and the final messageCheck narrow-screen layoutsSet the viewport to 375×812 and check whether the navigation bar and bottom buttons overlapReproduce an issueOpen the order list, navigate to a detail page, and return; check whether the filter is preservedRun regression checksVerify the updated login flow with a test account and confirm that it opens the home pageInformation lookup and summarizationOpen the specified page, locate the configuration instructions, and summarize the key pointsRecord browser actionsOpen the home page, record approximately 20 seconds of navigation to a detail page, and save it as a WebM file Screenshots support full-page and region capture. Browser recordings are saved as WebM files in the current workspace, with a maximum duration of 90 seconds per recording. Viewport Configuration For narrow-screen or mobile layout verification, ZCode Agent can resize the tab to a specific viewport size. The browser panel enters free-size mode, and a size toolbar appears below the address bar: Device preset: switch between common sizes such as Phone. Width × height: type pixel values directly, for example 390 × 844. Zoom: choose Fit to window or a fixed scale. You can also adjust these controls manually. Avoid changing the viewport size while ZCode Agent is operating, as this may affect its interpretation of the page state. Tab Management By default, the agent operates only tabs that it creates. To use a manually opened tab, specify the target page in the conversation and ask the agent to take control. The agent must explicitly claim the tab before performing any actions. Subagents can use the browser too, and share the same set of tabs with the current conversation. Tabs remain available across conversation turns until the tab or window is closed, or the application exits. They are not restored after a restart. The agent reuses existing tabs when accessing the same site. After a task, control can be returned to the user or retained for subsequent actions. Browser actions in background sessions do not switch the visible interface. They are displayed only when the corresponding workspace is in the foreground. Safety and Limitations The following limitations apply to browser automation: Page content is not a source of instructions. Page text is used to locate elements and understand the current state, rather than as instructions for the agent to execute. File uploads through browser control are not currently supported. Form steps that require a local file selection must be completed manually. Browser actions are governed by the execution mode, as are file changes and command execution. Ask before changes is recommended for actions that modify data, such as form submissions. Import Browser Data The built-in browser maintains a sign-in state separate from Chrome. Existing browser data can be imported to access websites that require authentication. Use Settings → Browser Use → Import browser data to import cookies and local storage from the most recently used Chrome profile. The import captures a snapshot of the data at that time; it does not synchronize continuously or modify Chrome data. On macOS, keychain access is required. On Windows, Chrome protects cookies with App-Bound encryption. The import asks you to approve administrator access once; ZCode starts a temporary system service for that import and deletes it right afterward. If you cancel, no cookies are imported. The import never reads passwords saved in Chrome. If Chrome is running, a profile lock may prevent the import. Close Chrome and retry. Clear Browser Data Browser data can be cleared from the same settings page: ActionWhat it removesSign-in stateClear built-in browser cacheHTTP cache, Cache Storage, and service workersKeptClear all browser dataCookies, site data, cache, and recent visitsSign-in required again in the built-in browser Clearing all browser data cannot be undone and requires confirmation. Browser data management is available only on desktop. Manual Browsing The browser panel can be used manually without enabling browser control. It provides an address bar, back, forward, reload, and DevTools controls, and supports http, https, and file URLs. In a local workspace, right-click an HTML file in the file tree and select Open in built-in browser to preview it in a new tab. After you turn on Open HTML files in the built-in browser on click under "Opening files" in Settings → Browser Use, clicking a local HTML file in the file tree also opens it in the built-in browser. Use the element picker in the panel to add page elements to the conversation context. See Turn page elements into context. Next Steps ZCode AgentLearn the prompt entry, model picker, and execution modes.PluginBrowser automation ships as an official plugin — see how plugins are installed and managed.ADE ToolsHow the file tree, terminal, preview panel, and review flow work together.

评论 (0)