Skip to main content
Glama

screenshot

Capture webpage screenshots with labeled interactive elements for visual web navigation and automated testing.

Instructions

Take a screenshot of the current page with labeled elements

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Tool registration for 'screenshot' with name, description, and inputSchema (no parameters required)
    Tool(
        name="screenshot",
        description="Take a screenshot of the current page with labeled elements",
        inputSchema={
            "type": "object",
            "properties": {}
        }
    ),
  • Handler that routes 'screenshot' tool calls to browser.execute with action='observe'
    elif name == "screenshot":
        result = await asyncio.to_thread(
            browser.execute,
            action="observe"
        )
  • Core implementation of screenshot functionality via _observe() method: injects Set-of-Mark labels, captures screenshot, returns labeled elements and base64 image
    def _observe(self, **_) -> BrowserResult:
        """Get visual observation of current page"""
        if self._page is None:
            return BrowserResult(success=False, error="No page open. Use navigate first.")
        
        try:
            self._page.wait_for_timeout(500)
            
            elements = self._page.evaluate(self.SOM_INJECT_SCRIPT)
            
            self._element_map = {}
            for el in elements:
                self._element_map[el['id']] = {
                    'x': el['x'],
                    'y': el['y'],
                    'width': el['width'],
                    'height': el['height'],
                    'tag': el['tag'],
                    'type': el['type'],
                    'text': el['text']
                }
            
            screenshot_bytes = self._page.screenshot(
                type="jpeg",
                quality=self.SCREENSHOT_QUALITY
            )
            screenshot_base64 = base64.b64encode(screenshot_bytes).decode('utf-8')
            
            elements_for_llm = []
            for el in elements:
                element_info = {
                    'id': el['id'],
                    'tag': el['tag'],
                }
                if el['text']:
                    element_info['text'] = el['text']
                if el['type']:
                    element_info['type'] = el['type']
                elements_for_llm.append(element_info)
            
            return BrowserResult(
                success=True,
                data={
                    'url': self._page.url,
                    'title': self._page.title(),
                    'screenshot': screenshot_base64,
                    'elements': elements_for_llm,
                    'element_count': len(elements)
                },
                metadata={'has_image': True}
            )
            
        except Exception as e:
            return BrowserResult(
                success=False,
                error=f"Observation failed: {str(e)}"
            )
  • SOM_INJECT_SCRIPT: JavaScript that injects numeric labels [N] onto interactive elements (links, buttons, inputs, etc.) for visual identification
    SOM_INJECT_SCRIPT = """
    () => {
        // Remove old labels
        document.querySelectorAll('.atlas-som-label').forEach(el => el.remove());
        
        const selectors = [
            'a[href]',
            'button',
            'input:not([type="hidden"])',
            'select',
            'textarea',
            '[role="button"]',
            '[role="link"]',
            '[role="checkbox"]',
            '[role="menuitem"]',
            '[onclick]',
            '[tabindex]:not([tabindex="-1"])'
        ];
        
        const elements = [];
        let labelId = 0;
        
        function markElements(doc, offsetX = 0, offsetY = 0) {
            if (!doc) return;
            
            selectors.forEach(selector => {
                try {
                    doc.querySelectorAll(selector).forEach(el => {
                        const rect = el.getBoundingClientRect();
                        const style = window.getComputedStyle(el);
                        
                        if (
                            rect.width <= 0 || 
                            rect.height <= 0 ||
                            style.visibility === 'hidden' ||
                            style.display === 'none' ||
                            parseFloat(style.opacity) === 0
                        ) {
                            return;
                        }
                        
                        const viewportWidth = window.innerWidth;
                        const viewportHeight = window.innerHeight;
                        
                        if (
                            rect.right < 0 || 
                            rect.bottom < 0 ||
                            rect.left > viewportWidth ||
                            rect.top > viewportHeight
                        ) {
                            return;
                        }
                        
                        const label = document.createElement('div');
                        label.className = 'atlas-som-label';
                        label.textContent = labelId;
                        label.style.cssText = `
                            position: fixed !important;
                            left: ${rect.left + offsetX}px !important;
                            top: ${rect.top + offsetY}px !important;
                            background: #FFFF00 !important;
                            color: #000000 !important;
                            border: 2px solid #FF0000 !important;
                            font-size: 12px !important;
                            font-weight: bold !important;
                            font-family: monospace !important;
                            padding: 1px 4px !important;
                            z-index: 2147483647 !important;
                            pointer-events: none !important;
                            border-radius: 3px !important;
                            line-height: 1.2 !important;
                        `;
                        document.body.appendChild(label);
                        
                        let text = '';
                        if (el.tagName === 'INPUT') {
                            text = el.placeholder || el.value || el.name || '';
                        } else if (el.tagName === 'SELECT') {
                            text = el.options[el.selectedIndex]?.text || '';
                        } else {
                            text = el.innerText || el.textContent || el.getAttribute('aria-label') || '';
                        }
                        text = text.trim().substring(0, 50);
                        
                        elements.push({
                            id: labelId,
                            x: Math.round(rect.left + rect.width / 2 + offsetX),
                            y: Math.round(rect.top + rect.height / 2 + offsetY),
                            width: Math.round(rect.width),
                            height: Math.round(rect.height),
                            tag: el.tagName.toLowerCase(),
                            type: el.type || '',
                            text: text
                        });
                        
                        labelId++;
                    });
                } catch (e) {}
            });
            
            try {
                doc.querySelectorAll('iframe').forEach(iframe => {
                    try {
                        const iframeRect = iframe.getBoundingClientRect();
                        const iframeDoc = iframe.contentDocument || iframe.contentWindow?.document;
                        if (iframeDoc) {
                            markElements(
                                iframeDoc, 
                                offsetX + iframeRect.left, 
                                offsetY + iframeRect.top
                            );
                        }
                    } catch (e) {}
                });
            } catch (e) {}
        }
        
        markElements(document);
        return elements;
    }
    """
  • Input schema definition for screenshot tool (empty object - no parameters required)
    inputSchema={
        "type": "object",
        "properties": {}
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool takes a screenshot and labels elements, but doesn't explain what 'labeled elements' means, whether this requires specific permissions, how the output is formatted, or if there are any side effects like pausing the page. This leaves significant gaps for a tool that interacts with a page.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action ('Take a screenshot') and adds a key detail ('with labeled elements') without any wasted words. Every part of the sentence contributes directly to understanding the tool's purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of interacting with a page (implied by sibling tools like 'click'), no annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like how labeling works, output format, or error conditions, which are crucial for a screenshot tool in this context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters with 100% coverage, so no parameters need documentation. The description adds value by specifying 'with labeled elements', which provides context beyond the empty schema, though it's minimal. Baseline for 0 parameters is 4, as the description compensates adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Take a screenshot') and the target ('current page'), with the additional detail 'with labeled elements' specifying what distinguishes this screenshot. However, it doesn't explicitly differentiate from potential sibling tools like 'click' or 'navigate' that might also involve page interaction, so it's not a perfect 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'click' or 'navigate', nor does it mention prerequisites such as needing a page to be loaded first. It implies usage by describing the action but lacks explicit context or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/LingTravel/Atlas-Browser'

If you have feedback or need assistance with the MCP directory API, please join our Discord server