Spaces:
Paused
Paused
| """ | |
| Advanced feature tabs for the UI | |
| """ | |
| import gradio as gr | |
| from features.http_requests import make_http_request, export_as_curl, get_request_history | |
| from features.advanced import wait_for_element, scroll_page, hover_element, press_key | |
| from features.extraction import get_page_info | |
| from features.monitoring import monitor_network_requests, get_console_logs | |
| from features.accessibility import accessibility_audit, check_color_contrast | |
| from features.analysis import ( | |
| extract_structured_data, visual_regression_test, | |
| extract_all_links, seo_analysis | |
| ) | |
| def create_advanced_tabs(): | |
| """Create tabs for advanced browser features""" | |
| with gr.Tab("π HTTP Request"): | |
| with gr.Row(): | |
| url_in_http = gr.Textbox(label="URL", value="https://api.example.com/data") | |
| method_in = gr.Dropdown( | |
| ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"], | |
| value="GET", | |
| label="Method" | |
| ) | |
| persist_check_http = gr.Checkbox(label="Use Persistent Browser", value=False) | |
| headers_in = gr.Code( | |
| label="Headers (JSON or key:value format)", | |
| language="json", | |
| lines=5, | |
| value='{\n "Content-Type": "application/json",\n "User-Agent": "MCP-Browser/1.0"\n}' | |
| ) | |
| data_in = gr.Code( | |
| label="Body Data (for POST/PUT/PATCH)", | |
| language="json", | |
| lines=5, | |
| value='{\n "key": "value"\n}' | |
| ) | |
| with gr.Row(): | |
| out_http = gr.Code(label="Response", language="json", lines=15) | |
| curl_out = gr.Textbox(label="cURL Command", lines=5) | |
| with gr.Row(): | |
| gr.Button("Send Request", variant="primary").click( | |
| make_http_request, | |
| [url_in_http, method_in, headers_in, data_in, persist_check_http], | |
| out_http | |
| ) | |
| gr.Button("Export as cURL", variant="secondary").click( | |
| export_as_curl, | |
| [method_in, url_in_http, headers_in, data_in], | |
| curl_out | |
| ) | |
| with gr.Row(): | |
| history_out = gr.Code(label="Request History", language="json", lines=10) | |
| gr.Button("Show History", variant="secondary").click( | |
| get_request_history, [], history_out | |
| ) | |
| with gr.Tab("β³ Wait for Element"): | |
| with gr.Row(): | |
| url_in_wait = gr.Textbox(label="URL") | |
| sel_in_wait = gr.Textbox(label="CSS Selector", placeholder=".dynamic-content") | |
| timeout_in = gr.Slider(minimum=1, maximum=60, value=10, label="Timeout (seconds)") | |
| persist_check_wait = gr.Checkbox(label="Use Persistent Browser", value=False) | |
| out_wait = gr.Textbox(label="Result", lines=3) | |
| gr.Button("Wait for Element", variant="primary").click( | |
| wait_for_element, | |
| [url_in_wait, sel_in_wait, timeout_in, persist_check_wait], | |
| out_wait | |
| ) | |
| with gr.Tab("π Scroll"): | |
| with gr.Row(): | |
| url_in_scroll = gr.Textbox(label="URL") | |
| direction_in = gr.Radio(["bottom", "top", "down", "up"], value="bottom", label="Direction") | |
| pixels_in = gr.Number(label="Pixels (for up/down)", value=500) | |
| persist_check_scroll = gr.Checkbox(label="Use Persistent Browser", value=False) | |
| out_scroll = gr.Textbox(label="Result", lines=2) | |
| gr.Button("Scroll", variant="primary").click( | |
| scroll_page, | |
| [url_in_scroll, direction_in, pixels_in, persist_check_scroll], | |
| out_scroll | |
| ) | |
| with gr.Tab("π― Hover"): | |
| with gr.Row(): | |
| url_in_hover = gr.Textbox(label="URL") | |
| sel_in_hover = gr.Textbox(label="CSS Selector", placeholder=".menu-item") | |
| persist_check_hover = gr.Checkbox(label="Use Persistent Browser", value=False) | |
| out_hover = gr.Textbox(label="Result", lines=2) | |
| gr.Button("Hover", variant="primary").click( | |
| hover_element, [url_in_hover, sel_in_hover, persist_check_hover], out_hover | |
| ) | |
| with gr.Tab("β¨οΈ Press Key"): | |
| with gr.Row(): | |
| url_in_key = gr.Textbox(label="URL") | |
| key_in = gr.Textbox(label="Key", placeholder="enter, escape, tab, etc.") | |
| sel_in_key = gr.Textbox(label="Target Element", value="body") | |
| persist_check_key = gr.Checkbox(label="Use Persistent Browser", value=False) | |
| out_key = gr.Textbox(label="Result", lines=2) | |
| gr.Button("Press Key", variant="primary").click( | |
| press_key, | |
| [url_in_key, key_in, sel_in_key, persist_check_key], | |
| out_key | |
| ) | |
| with gr.Tab("βΉοΈ Page Info"): | |
| with gr.Row(): | |
| url_in_info = gr.Textbox(label="URL") | |
| persist_check_info = gr.Checkbox(label="Use Persistent Browser", value=False) | |
| out_info = gr.Textbox(label="Page Information", lines=15) | |
| gr.Button("Get Info", variant="primary").click( | |
| get_page_info, [url_in_info, persist_check_info], out_info | |
| ) | |
| with gr.Tab("π Network Monitor"): | |
| with gr.Row(): | |
| url_in_network = gr.Textbox(label="URL", value="https://example.com") | |
| duration_in = gr.Slider(minimum=1, maximum=30, value=5, label="Monitor Duration (seconds)") | |
| persist_check_network = gr.Checkbox(label="Use Persistent Browser", value=False) | |
| out_network = gr.Code(label="Network Requests", language="json", lines=15) | |
| gr.Button("Monitor Network", variant="primary").click( | |
| monitor_network_requests, | |
| [url_in_network, duration_in, persist_check_network], | |
| out_network | |
| ) | |
| # Console logs section | |
| with gr.Row(): | |
| out_console = gr.Code(label="Console Logs", language="json", lines=10) | |
| gr.Button("Get Console Logs", variant="secondary").click( | |
| get_console_logs, | |
| [url_in_network, persist_check_network], | |
| out_console | |
| ) | |
| with gr.Tab("π Structured Data"): | |
| with gr.Row(): | |
| url_in_structured = gr.Textbox(label="URL", value="https://example.com") | |
| persist_check_structured = gr.Checkbox(label="Use Persistent Browser", value=False) | |
| out_structured = gr.Code( | |
| label="Structured Data (JSON-LD, Meta, OpenGraph)", | |
| language="json", | |
| lines=15 | |
| ) | |
| gr.Button("Extract Structured Data", variant="primary").click( | |
| extract_structured_data, | |
| [url_in_structured, persist_check_structured], | |
| out_structured | |
| ) | |
| with gr.Tab("π¨ Visual Testing"): | |
| with gr.Row(): | |
| url1_in = gr.Textbox(label="URL 1", value="https://example.com") | |
| url2_in = gr.Textbox(label="URL 2", value="https://example.com/new") | |
| threshold_in = gr.Slider(minimum=0, maximum=1, value=0.98, label="Similarity Threshold") | |
| out_visual = gr.Code(label="Visual Comparison Result", language="json", lines=10) | |
| gr.Button("Compare Pages", variant="primary").click( | |
| visual_regression_test, | |
| [url1_in, url2_in, threshold_in], | |
| out_visual | |
| ) | |
| with gr.Tab("βΏ Accessibility"): | |
| with gr.Row(): | |
| url_in_a11y = gr.Textbox(label="URL", value="https://example.com") | |
| persist_check_a11y = gr.Checkbox(label="Use Persistent Browser", value=False) | |
| with gr.Row(): | |
| with gr.Column(): | |
| out_a11y = gr.Code(label="Accessibility Audit Results", language="json", lines=20) | |
| gr.Button("Run Full Audit", variant="primary").click( | |
| accessibility_audit, | |
| [url_in_a11y, persist_check_a11y], | |
| out_a11y | |
| ) | |
| with gr.Column(): | |
| out_contrast = gr.Code(label="Color Contrast Issues", language="json", lines=20) | |
| gr.Button("Check Color Contrast", variant="secondary").click( | |
| check_color_contrast, | |
| [url_in_a11y, persist_check_a11y], | |
| out_contrast | |
| ) | |
| with gr.Tab("π Link Extractor"): | |
| with gr.Row(): | |
| url_in_links = gr.Textbox(label="URL", value="https://example.com") | |
| include_external_check = gr.Checkbox(label="Include External Links", value=True) | |
| persist_check_links = gr.Checkbox(label="Use Persistent Browser", value=False) | |
| out_links = gr.Code(label="All Links (Categorized)", language="json", lines=20) | |
| gr.Button("Extract Links", variant="primary").click( | |
| extract_all_links, | |
| [url_in_links, include_external_check, persist_check_links], | |
| out_links | |
| ) | |
| with gr.Tab("π SEO Analysis"): | |
| with gr.Row(): | |
| url_in_seo = gr.Textbox(label="URL", value="https://example.com") | |
| persist_check_seo = gr.Checkbox(label="Use Persistent Browser", value=False) | |
| out_seo = gr.Code(label="SEO Analysis Results", language="json", lines=20) | |
| gr.Button("Analyze SEO", variant="primary").click( | |
| seo_analysis, | |
| [url_in_seo, persist_check_seo], | |
| out_seo | |
| ) | |
| gr.Markdown(""" | |
| ### π Advanced Features Guide: | |
| **π Network Monitor**: Captures XHR, fetch requests, and resource loading | |
| **π Structured Data**: Extracts JSON-LD, OpenGraph, Twitter Cards, microdata | |
| **βΏ Accessibility**: WCAG compliance checking with detailed recommendations | |
| **π¨ Visual Testing**: Compare two pages for visual differences | |
| **π Link Extractor**: Categorizes all links (internal, external, downloads, etc.) | |
| **π SEO Analysis**: Comprehensive SEO audit with scoring and recommendations | |
| **π Console Logs**: Capture browser console output for debugging | |
| All features support persistent browser sessions for faster sequential operations! | |
| """) |