Upload a ZIP file containing resources that your AI agent can use to complete tasks. The ZIP file is automatically extracted and made available to the agent.
import { chromium } from 'playwright';// 1. Create a test ZIP file with contentconst testContent = 'Hello from Anchor!\nThis is a test file for the agent.';const blob = new Blob([testContent], { type: 'text/plain' });const formData = new FormData();formData.append('file', blob, 'test-data.zip');// 2. Upload to browser sessionconst response = await fetch(`https://api.anchorbrowser.io/v1/sessions/${sessionId}/agent/files`, { method: 'POST', headers: { 'anchor-api-key': apiKey }, body: formData});const result = await response.json();console.log('Upload result:', result);// 3. Connect to the browser session and use uploaded files with AI agentconst browser = await chromium.connectOverCDP( `wss://connect.anchorbrowser.io?apiKey=${apiKey}&sessionId=${sessionId}`);const context = browser.contexts()[0];const page = context.pages()[0];// Navigate to a website where you want to use the uploaded filesawait page.goto('https://v0-download-and-upload-text.vercel.app/');// Use AI agent to interact with the page using uploaded filesconst ai = context.serviceWorkers()[0];const aiResult = await ai.evaluate("upload a file to the server");console.log('AI agent result:', aiResult);
That’s it! The agent can now access all uploaded files and use them to complete web tasks.