Spaces:
Running
Running
Update ui/tabs_advanced.py
Browse files- ui/tabs_advanced.py +119 -0
ui/tabs_advanced.py
CHANGED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Advanced feature tabs - placeholder for now
|
| 3 |
+
Note: The advanced features (HTTP requests, monitoring, accessibility, etc.)
|
| 4 |
+
need to be implemented in separate feature modules first
|
| 5 |
+
"""
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from features.http_requests import make_http_request, export_as_curl, get_request_history
|
| 8 |
+
from features.advanced import wait_for_element, scroll_page, hover_element, press_key
|
| 9 |
+
from features.extraction import get_page_info
|
| 10 |
+
|
| 11 |
+
def create_advanced_tabs():
|
| 12 |
+
"""Create tabs for advanced browser features"""
|
| 13 |
+
|
| 14 |
+
with gr.Tab("🔗 HTTP Request"):
|
| 15 |
+
with gr.Row():
|
| 16 |
+
url_in_http = gr.Textbox(label="URL", value="https://api.example.com/data")
|
| 17 |
+
method_in = gr.Dropdown(
|
| 18 |
+
["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"],
|
| 19 |
+
value="GET",
|
| 20 |
+
label="Method"
|
| 21 |
+
)
|
| 22 |
+
persist_check_http = gr.Checkbox(label="Use Persistent Browser", value=False)
|
| 23 |
+
|
| 24 |
+
headers_in = gr.Code(
|
| 25 |
+
label="Headers (JSON or key:value format)",
|
| 26 |
+
language="json",
|
| 27 |
+
lines=5,
|
| 28 |
+
value='{\n "Content-Type": "application/json",\n "User-Agent": "MCP-Browser/1.0"\n}'
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
data_in = gr.Code(
|
| 32 |
+
label="Body Data (for POST/PUT/PATCH)",
|
| 33 |
+
language="json",
|
| 34 |
+
lines=5,
|
| 35 |
+
value='{\n "key": "value"\n}'
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
with gr.Row():
|
| 39 |
+
out_http = gr.Code(label="Response", language="json", lines=15)
|
| 40 |
+
curl_out = gr.Textbox(label="cURL Command", lines=5)
|
| 41 |
+
|
| 42 |
+
with gr.Row():
|
| 43 |
+
gr.Button("Send Request", variant="primary").click(
|
| 44 |
+
make_http_request,
|
| 45 |
+
[url_in_http, method_in, headers_in, data_in, persist_check_http],
|
| 46 |
+
out_http
|
| 47 |
+
)
|
| 48 |
+
gr.Button("Export as cURL", variant="secondary").click(
|
| 49 |
+
export_as_curl,
|
| 50 |
+
[method_in, url_in_http, headers_in, data_in],
|
| 51 |
+
curl_out
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
with gr.Row():
|
| 55 |
+
history_out = gr.Code(label="Request History", language="json", lines=10)
|
| 56 |
+
gr.Button("Show History", variant="secondary").click(
|
| 57 |
+
get_request_history, [], history_out
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
with gr.Tab("⏳ Wait for Element"):
|
| 61 |
+
with gr.Row():
|
| 62 |
+
url_in_wait = gr.Textbox(label="URL")
|
| 63 |
+
sel_in_wait = gr.Textbox(label="CSS Selector", placeholder=".dynamic-content")
|
| 64 |
+
timeout_in = gr.Slider(minimum=1, maximum=60, value=10, label="Timeout (seconds)")
|
| 65 |
+
persist_check_wait = gr.Checkbox(label="Use Persistent Browser", value=False)
|
| 66 |
+
out_wait = gr.Textbox(label="Result", lines=3)
|
| 67 |
+
gr.Button("Wait for Element", variant="primary").click(
|
| 68 |
+
wait_for_element,
|
| 69 |
+
[url_in_wait, sel_in_wait, timeout_in, persist_check_wait],
|
| 70 |
+
out_wait
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
with gr.Tab("📜 Scroll"):
|
| 74 |
+
with gr.Row():
|
| 75 |
+
url_in_scroll = gr.Textbox(label="URL")
|
| 76 |
+
direction_in = gr.Radio(["bottom", "top", "down", "up"], value="bottom", label="Direction")
|
| 77 |
+
pixels_in = gr.Number(label="Pixels (for up/down)", value=500)
|
| 78 |
+
persist_check_scroll = gr.Checkbox(label="Use Persistent Browser", value=False)
|
| 79 |
+
out_scroll = gr.Textbox(label="Result", lines=2)
|
| 80 |
+
gr.Button("Scroll", variant="primary").click(
|
| 81 |
+
scroll_page,
|
| 82 |
+
[url_in_scroll, direction_in, pixels_in, persist_check_scroll],
|
| 83 |
+
out_scroll
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
with gr.Tab("🎯 Hover"):
|
| 87 |
+
with gr.Row():
|
| 88 |
+
url_in_hover = gr.Textbox(label="URL")
|
| 89 |
+
sel_in_hover = gr.Textbox(label="CSS Selector", placeholder=".menu-item")
|
| 90 |
+
persist_check_hover = gr.Checkbox(label="Use Persistent Browser", value=False)
|
| 91 |
+
out_hover = gr.Textbox(label="Result", lines=2)
|
| 92 |
+
gr.Button("Hover", variant="primary").click(
|
| 93 |
+
hover_element, [url_in_hover, sel_in_hover, persist_check_hover], out_hover
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
with gr.Tab("⌨️ Press Key"):
|
| 97 |
+
with gr.Row():
|
| 98 |
+
url_in_key = gr.Textbox(label="URL")
|
| 99 |
+
key_in = gr.Textbox(label="Key", placeholder="enter, escape, tab, etc.")
|
| 100 |
+
sel_in_key = gr.Textbox(label="Target Element", value="body")
|
| 101 |
+
persist_check_key = gr.Checkbox(label="Use Persistent Browser", value=False)
|
| 102 |
+
out_key = gr.Textbox(label="Result", lines=2)
|
| 103 |
+
gr.Button("Press Key", variant="primary").click(
|
| 104 |
+
press_key,
|
| 105 |
+
[url_in_key, key_in, sel_in_key, persist_check_key],
|
| 106 |
+
out_key
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
with gr.Tab("ℹ️ Page Info"):
|
| 110 |
+
with gr.Row():
|
| 111 |
+
url_in_info = gr.Textbox(label="URL")
|
| 112 |
+
persist_check_info = gr.Checkbox(label="Use Persistent Browser", value=False)
|
| 113 |
+
out_info = gr.Textbox(label="Page Information", lines=15)
|
| 114 |
+
gr.Button("Get Info", variant="primary").click(
|
| 115 |
+
get_page_info, [url_in_info, persist_check_info], out_info
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
# Note: Additional advanced features like Network Monitor, Accessibility Audit,
|
| 119 |
+
# Visual Testing, etc. would need their respective feature modules to be implemented
|