← Back to recipes

Capture network traffic

Enable network capture, load a page, and inspect the requests Guida observed.

Network and HTTP Intermediate JavaScript capture_network.js

Prerequisites

None.

Expected result

Guida captures recent requests and logs method, status, content type, and URL snippets.

Source example

capture_network.js

Network capture helps you understand what a page loads and can reveal API endpoints behind a web interface.

// Capture Network Traffic — Monitor HTTP requests
//
// This script enables network capture, navigates to a page,
// and inspects the HTTP requests that were made. Useful for
// finding API endpoints and understanding page behavior.
// Ensure we have a browser tab
await g.tabs.newBrowserTab();
// Enable network capture
g.network.enable();
g.log("Network capture enabled. Navigating...");
// Navigate to trigger some requests
await g.nav.navigateToUrl("https://example.com");
// Wait a moment for requests to be captured
await g.wait(2000);
// Search captured traffic
const traffic = g.network.search(null, {
limit: 10
});
g.log("Captured " + traffic.length + " request(s):");
for (const entry of traffic) {
const status = entry.responseStatusCode || "pending";
const type = entry.contentType || "unknown";
g.log(" " + entry.method + " " + status +
" " + type + "" + entry.url.substring(0, 80));
}
// You can also wait for a specific request pattern
// const req = await g.network.waitForRequest("*/api/*", {
// timeout: 10000
// });
g.log("Done! Check the History pane > Network tab for details.");