// Start automation and embed the live preview
const response = await fetch("https://agent.tinyfish.ai/v1/automation/run-sse", {
method: "POST",
headers: {
"X-API-Key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://example.com/products",
goal: "Extract all product names and prices",
}),
});
// Parse SSE events to find the streaming URL
for await (const chunk of response.body) {
const text = new TextDecoder().decode(chunk);
for (const line of text.split("\n")) {
if (!line.startsWith("data: ")) continue;
const event = JSON.parse(line.slice(6));
if (event.type === "STREAMING_URL") {
// Set iframe src to show the live browser
document.getElementById("preview").src = event.streaming_url;
}
}
}