Browser Automation Examples¶
Examples showing how to use Gobbler's browser automation capabilities.
Prerequisites¶
- Gobbler MCP server or CLI installed
- Browser extension installed and connected
- Target tabs in the "Gobbler" tab group
Example 1: Extract Current Page¶
The simplest use case - extract the current browser page as markdown.
MCP Tool: browser_extract_current_page()
Example 2: Extract Specific Content¶
Extract only a specific section using CSS selectors.
Common selectors:
| Content Type | Selector |
|---|---|
| Main article | article, .post-content |
| Documentation | main, .docs-content |
| GitHub README | .markdown-body |
Example 3: Navigate and Extract¶
Navigate to a URL and extract its content.
# Navigate
gobbler browser navigate "https://docs.python.org/3/tutorial/"
# Extract
gobbler browser extract -o tutorial.md
Example 4: Execute JavaScript¶
Run JavaScript in the browser to get specific information.
# Get page title
gobbler browser exec "document.title"
# Get all image URLs
gobbler browser exec "Array.from(document.querySelectorAll('img')).map(img => img.src)"
# Count elements
gobbler browser exec "document.querySelectorAll('h1').length"
Example 5: Get Page Metadata¶
gobbler browser exec "({
title: document.title,
url: window.location.href,
links: document.querySelectorAll('a').length,
images: document.querySelectorAll('img').length
})"
Example 6: Multi-Step Workflow¶
Search Wikipedia and extract the result:
# Navigate to Wikipedia
gobbler browser navigate "https://en.wikipedia.org"
# Fill search and submit
gobbler browser exec "
document.querySelector('#searchInput').value = 'Python programming';
document.querySelector('form').submit();
"
# Wait for page load, then extract
sleep 2
gobbler browser extract --selector "#content" -o python.md
Example 7: Data Collection¶
Extract structured data from a page:
gobbler browser exec "
Array.from(document.querySelectorAll('.blog-post')).map(post => ({
title: post.querySelector('h2')?.textContent,
url: post.querySelector('a')?.href,
excerpt: post.querySelector('.excerpt')?.textContent
}))
"
Example 8: Check Element Existence¶
gobbler browser exec "
const loginBtn = document.querySelector('button.login, a.login, #login-btn');
loginBtn ? { found: true, text: loginBtn.textContent } : { found: false }
"
Example 9: Form Automation¶
Fill out a form (use with caution):
gobbler browser exec "
document.querySelector('#name').value = 'John Doe';
document.querySelector('#email').value = 'john@example.com';
document.querySelector('#message').value = 'Test message';
"
Example 10: Connection Check¶
Always check connection before operations:
Tips for Best Results¶
-
Always check connection first
-
Use selectors for targeted extraction
--selector "article"- Main article--selector ".content"- Element with class-
--selector "#main"- Element with id -
Handle timeouts appropriately
-
Wait for dynamic content
Security Best Practices¶
- Never execute untrusted scripts
- Be cautious with form automation - only automate your own forms
- Don't store sensitive data in extracted markdown
- Use HTTPS when navigating programmatically
- Validate input before passing to JavaScript execution
Troubleshooting¶
Extension not connected: - Check extension is installed at chrome://extensions/ - Verify extension popup shows "Connected"
Commands timing out: - Increase timeout: --timeout 60 - Check browser tab is active - Verify page has loaded completely
Script execution errors: - Check JavaScript syntax - Verify selectors exist on page - Test scripts in browser DevTools first
Navigation not working: - Ensure URL is valid and complete - Check for popups blocking navigation