Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions docs/configuration/observability.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,66 @@ Each operation creates detailed logs for analysis:
</Accordion>
</AccordionGroup>

## Action History Tracking

Track all Stagehand operations with the built-in action history feature. The `stagehand.history` property provides a chronological record of every method call during your automation session.

### Accessing History Data

Get a complete history of all Stagehand operations performed in the current session:

<CodeGroup>
```typescript TypeScript
import { Stagehand } from "@browserbasehq/stagehand";

const stagehand = new Stagehand({ env: "LOCAL" });
await stagehand.init();

// Perform various operations
await stagehand.page.goto("https://example.com");
await stagehand.page.act("click the login button");
const userInfo = await stagehand.page.extract("extract user profile data");
const elements = await stagehand.page.observe("find all navigation links");

// Access complete operation history
const history = stagehand.history;
console.log('Total operations:', history.length);

// Examine individual entries
history.forEach((entry, index) => {
console.log(`Operation ${index + 1}:`, {
method: entry.method,
timestamp: entry.timestamp,
hasResult: entry.result !== null
});
});
```

```python Python
from stagehand import Stagehand

stagehand = Stagehand(env="LOCAL")
await stagehand.init()

# Perform various operations
await stagehand.page.goto("https://example.com")
await stagehand.page.act("click the login button")
user_info = await stagehand.page.extract("extract user profile data")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: should be user_info to follow snake_case convention for Python variables

Suggested change
user_info = await stagehand.page.extract("extract user profile data")
user_info = await stagehand.page.extract("extract user profile data")

Context Used: Rule - Use camelCase naming convention for TypeScript code and snake_case naming convention for Python code in documentation examples. (link)

elements = await stagehand.page.observe("find all navigation links")

# Access complete operation history
history = stagehand.history
print(f'Total operations: {len(history)}')

# Examine individual entries
for index, entry in enumerate(history):
print(f"Operation {index + 1}:", {
'method': entry['method'],
'timestamp': entry['timestamp'],
'has_result': entry['result'] is not None
})
```
</CodeGroup>


For detailed logging and debugging capabilities, see [Logging](/configuration/logging).