webtap-tool 0.2.3__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webtap-tool might be problematic. Click here for more details.
- webtap/__init__.py +2 -27
- webtap/api.py +0 -15
- webtap/app.py +1 -0
- webtap/commands/server.py +162 -0
- {webtap_tool-0.2.3.dist-info → webtap_tool-0.3.0.dist-info}/METADATA +1 -1
- {webtap_tool-0.2.3.dist-info → webtap_tool-0.3.0.dist-info}/RECORD +8 -7
- {webtap_tool-0.2.3.dist-info → webtap_tool-0.3.0.dist-info}/WHEEL +0 -0
- {webtap_tool-0.2.3.dist-info → webtap_tool-0.3.0.dist-info}/entry_points.txt +0 -0
webtap/__init__.py
CHANGED
|
@@ -9,14 +9,9 @@ PUBLIC API:
|
|
|
9
9
|
- main: Entry point function for CLI
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
|
-
import atexit
|
|
13
12
|
import sys
|
|
14
|
-
import logging
|
|
15
13
|
|
|
16
14
|
from webtap.app import app
|
|
17
|
-
from webtap.api import start_api_server
|
|
18
|
-
|
|
19
|
-
logger = logging.getLogger(__name__)
|
|
20
15
|
|
|
21
16
|
|
|
22
17
|
def main():
|
|
@@ -27,13 +22,9 @@ def main():
|
|
|
27
22
|
- MCP mode (with --mcp flag) for Model Context Protocol server
|
|
28
23
|
- REPL mode (default) for interactive shell
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
The API server for Chrome extension communication must be started
|
|
26
|
+
explicitly using the server('start') command.
|
|
32
27
|
"""
|
|
33
|
-
# Start API server for Chrome extension (except in CLI mode)
|
|
34
|
-
if "--cli" not in sys.argv:
|
|
35
|
-
_start_api_server_safely()
|
|
36
|
-
|
|
37
28
|
if "--mcp" in sys.argv:
|
|
38
29
|
app.mcp.run()
|
|
39
30
|
elif "--cli" in sys.argv:
|
|
@@ -45,20 +36,4 @@ def main():
|
|
|
45
36
|
app.run(title="WebTap - Chrome DevTools Protocol REPL")
|
|
46
37
|
|
|
47
38
|
|
|
48
|
-
def _start_api_server_safely():
|
|
49
|
-
"""Start API server with error handling and cleanup registration."""
|
|
50
|
-
try:
|
|
51
|
-
thread = start_api_server(app.state)
|
|
52
|
-
if thread and app.state:
|
|
53
|
-
app.state.api_thread = thread
|
|
54
|
-
logger.info("API server started on port 8765")
|
|
55
|
-
|
|
56
|
-
# Register cleanup to shut down API server on exit
|
|
57
|
-
atexit.register(lambda: app.state.cleanup() if app.state else None)
|
|
58
|
-
else:
|
|
59
|
-
logger.info("Port 8765 in use by another instance")
|
|
60
|
-
except Exception as e:
|
|
61
|
-
logger.warning(f"Failed to start API server: {e}")
|
|
62
|
-
|
|
63
|
-
|
|
64
39
|
__all__ = ["app", "main"]
|
webtap/api.py
CHANGED
|
@@ -199,21 +199,6 @@ async def disable_all_filters() -> Dict[str, Any]:
|
|
|
199
199
|
return {"enabled": [], "total": 0}
|
|
200
200
|
|
|
201
201
|
|
|
202
|
-
@api.post("/release")
|
|
203
|
-
async def release_port() -> Dict[str, Any]:
|
|
204
|
-
"""Release API port for another WebTap instance."""
|
|
205
|
-
logger.info("Releasing API port for another instance")
|
|
206
|
-
|
|
207
|
-
# Schedule graceful shutdown after response
|
|
208
|
-
def shutdown():
|
|
209
|
-
# Just set the flag to stop uvicorn, don't kill the whole process
|
|
210
|
-
global _shutdown_requested
|
|
211
|
-
_shutdown_requested = True
|
|
212
|
-
|
|
213
|
-
threading.Timer(0.5, shutdown).start()
|
|
214
|
-
return {"message": "Releasing port 8765"}
|
|
215
|
-
|
|
216
|
-
|
|
217
202
|
# Flag to signal shutdown
|
|
218
203
|
_shutdown_requested = False
|
|
219
204
|
|
webtap/app.py
CHANGED
|
@@ -84,6 +84,7 @@ else:
|
|
|
84
84
|
from webtap.commands import inspect # noqa: E402, F401
|
|
85
85
|
from webtap.commands import fetch # noqa: E402, F401
|
|
86
86
|
from webtap.commands import body # noqa: E402, F401
|
|
87
|
+
from webtap.commands import server # noqa: E402, F401
|
|
87
88
|
from webtap.commands import setup # noqa: E402, F401
|
|
88
89
|
from webtap.commands import launch # noqa: E402, F401
|
|
89
90
|
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""API server management command.
|
|
2
|
+
|
|
3
|
+
PUBLIC API:
|
|
4
|
+
- server: Manage API server (status/start/stop/restart)
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import socket
|
|
8
|
+
import time
|
|
9
|
+
import logging
|
|
10
|
+
|
|
11
|
+
from webtap.app import app
|
|
12
|
+
from webtap.api import start_api_server
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
# Fixed port for API server
|
|
17
|
+
API_PORT = 8765
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _check_port() -> bool:
|
|
21
|
+
"""Check if API port is in use."""
|
|
22
|
+
with socket.socket() as s:
|
|
23
|
+
try:
|
|
24
|
+
s.bind(("127.0.0.1", API_PORT))
|
|
25
|
+
return False # Port is free
|
|
26
|
+
except OSError:
|
|
27
|
+
return True # Port is in use
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _stop_server(state) -> tuple[bool, str]:
|
|
31
|
+
"""Stop the server if this instance owns it."""
|
|
32
|
+
if not state.api_thread or not state.api_thread.is_alive():
|
|
33
|
+
return False, "Not running"
|
|
34
|
+
|
|
35
|
+
import webtap.api
|
|
36
|
+
|
|
37
|
+
webtap.api._shutdown_requested = True
|
|
38
|
+
state.api_thread.join(timeout=2.0)
|
|
39
|
+
state.api_thread = None
|
|
40
|
+
|
|
41
|
+
return True, "Server stopped"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _start_server(state) -> tuple[bool, str]:
|
|
45
|
+
"""Start the server on port 8765."""
|
|
46
|
+
# Check if already running
|
|
47
|
+
if state.api_thread and state.api_thread.is_alive():
|
|
48
|
+
return True, f"Already running on port {API_PORT}"
|
|
49
|
+
|
|
50
|
+
# Check if port is in use
|
|
51
|
+
if _check_port():
|
|
52
|
+
return False, f"Port {API_PORT} already in use by another process"
|
|
53
|
+
|
|
54
|
+
# Start the server
|
|
55
|
+
thread = start_api_server(state, port=API_PORT)
|
|
56
|
+
if thread:
|
|
57
|
+
state.api_thread = thread
|
|
58
|
+
|
|
59
|
+
# Register cleanup
|
|
60
|
+
import atexit
|
|
61
|
+
|
|
62
|
+
atexit.register(lambda: state.cleanup() if state else None)
|
|
63
|
+
|
|
64
|
+
return True, f"Server started on port {API_PORT}"
|
|
65
|
+
else:
|
|
66
|
+
return False, "Failed to start server"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@app.command(
|
|
70
|
+
display="markdown",
|
|
71
|
+
fastmcp={
|
|
72
|
+
"type": "prompt",
|
|
73
|
+
"arg_descriptions": {"action": "Server action: status (default), start, stop, or restart"},
|
|
74
|
+
},
|
|
75
|
+
)
|
|
76
|
+
def server(state, action: str = None) -> dict: # pyright: ignore[reportArgumentType]
|
|
77
|
+
"""API server status and management information.
|
|
78
|
+
|
|
79
|
+
Returns current server state and available actions.
|
|
80
|
+
"""
|
|
81
|
+
if action is None:
|
|
82
|
+
action = "status"
|
|
83
|
+
|
|
84
|
+
action = action.lower()
|
|
85
|
+
owns_server = bool(state.api_thread and state.api_thread.is_alive())
|
|
86
|
+
|
|
87
|
+
# Build markdown elements based on action
|
|
88
|
+
elements = []
|
|
89
|
+
|
|
90
|
+
if action == "status" or action not in ["start", "stop", "restart"]:
|
|
91
|
+
# Status information
|
|
92
|
+
elements.append({"type": "heading", "content": "API Server Status", "level": 2})
|
|
93
|
+
|
|
94
|
+
if owns_server:
|
|
95
|
+
elements.append({"type": "text", "content": "**Status:** Running"})
|
|
96
|
+
elements.append({"type": "text", "content": f"**Port:** {API_PORT}"})
|
|
97
|
+
elements.append({"type": "text", "content": f"**URL:** http://127.0.0.1:{API_PORT}"})
|
|
98
|
+
elements.append({"type": "text", "content": f"**Health:** http://127.0.0.1:{API_PORT}/health"})
|
|
99
|
+
elements.append({"type": "text", "content": "**Extension:** Ready to connect"})
|
|
100
|
+
else:
|
|
101
|
+
port_in_use = _check_port()
|
|
102
|
+
if port_in_use:
|
|
103
|
+
elements.append({"type": "alert", "message": "Port 8765 in use by another process", "level": "warning"})
|
|
104
|
+
elements.append({"type": "text", "content": "Cannot start server until port is free"})
|
|
105
|
+
else:
|
|
106
|
+
elements.append({"type": "text", "content": "**Status:** Not running"})
|
|
107
|
+
elements.append({"type": "text", "content": f"**Port:** {API_PORT} (available)"})
|
|
108
|
+
elements.append({"type": "text", "content": "Use `server('start')` to start the API server"})
|
|
109
|
+
|
|
110
|
+
# Available actions
|
|
111
|
+
elements.append({"type": "heading", "content": "Available Actions", "level": 3})
|
|
112
|
+
actions = [
|
|
113
|
+
"`server('start')` - Start the API server",
|
|
114
|
+
"`server('stop')` - Stop the API server",
|
|
115
|
+
"`server('restart')` - Restart the API server",
|
|
116
|
+
"`server('status')` or `server()` - Show this status",
|
|
117
|
+
]
|
|
118
|
+
elements.append({"type": "list", "items": actions})
|
|
119
|
+
|
|
120
|
+
elif action == "start":
|
|
121
|
+
if owns_server:
|
|
122
|
+
elements.append({"type": "alert", "message": f"Server already running on port {API_PORT}", "level": "info"})
|
|
123
|
+
else:
|
|
124
|
+
success, message = _start_server(state)
|
|
125
|
+
if success:
|
|
126
|
+
elements.append({"type": "alert", "message": message, "level": "success"})
|
|
127
|
+
elements.append({"type": "text", "content": f"**URL:** http://127.0.0.1:{API_PORT}"})
|
|
128
|
+
elements.append({"type": "text", "content": f"**Health:** http://127.0.0.1:{API_PORT}/health"})
|
|
129
|
+
elements.append({"type": "text", "content": "Chrome extension can now connect"})
|
|
130
|
+
else:
|
|
131
|
+
elements.append({"type": "alert", "message": message, "level": "error"})
|
|
132
|
+
|
|
133
|
+
elif action == "stop":
|
|
134
|
+
if not owns_server:
|
|
135
|
+
elements.append({"type": "text", "content": "Server not running"})
|
|
136
|
+
else:
|
|
137
|
+
success, message = _stop_server(state)
|
|
138
|
+
if success:
|
|
139
|
+
elements.append({"type": "alert", "message": message, "level": "success"})
|
|
140
|
+
else:
|
|
141
|
+
elements.append({"type": "alert", "message": message, "level": "error"})
|
|
142
|
+
|
|
143
|
+
elif action == "restart":
|
|
144
|
+
if owns_server:
|
|
145
|
+
success, msg = _stop_server(state)
|
|
146
|
+
if not success:
|
|
147
|
+
elements.append({"type": "alert", "message": f"Failed to stop: {msg}", "level": "error"})
|
|
148
|
+
return {"elements": elements}
|
|
149
|
+
time.sleep(0.5)
|
|
150
|
+
|
|
151
|
+
success, msg = _start_server(state)
|
|
152
|
+
if success:
|
|
153
|
+
elements.append({"type": "alert", "message": "Server restarted", "level": "success"})
|
|
154
|
+
elements.append({"type": "text", "content": f"**Port:** {API_PORT}"})
|
|
155
|
+
elements.append({"type": "text", "content": f"**URL:** http://127.0.0.1:{API_PORT}"})
|
|
156
|
+
else:
|
|
157
|
+
elements.append({"type": "alert", "message": f"Failed to restart: {msg}", "level": "error"})
|
|
158
|
+
|
|
159
|
+
return {"elements": elements}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
__all__ = ["server"]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
webtap/VISION.md,sha256=kfoJfEPVc4chOrD9tNMDmYBY9rX9KB-286oZj70ALCE,7681
|
|
2
|
-
webtap/__init__.py,sha256=
|
|
3
|
-
webtap/api.py,sha256=
|
|
4
|
-
webtap/app.py,sha256=
|
|
2
|
+
webtap/__init__.py,sha256=DFWJGmqZfX8_h4csLA5pKPR4SkaHBMlUgU-WQIE96Gw,1092
|
|
3
|
+
webtap/api.py,sha256=QLfwO_21uSyxBCsqei45c5Uyg7OVfaVopmBncx9ZRfw,8018
|
|
4
|
+
webtap/app.py,sha256=OC8-767GtQ_hAOxUNqD6Yu3JYLNB3ZXdzKn-A1S_RJI,3305
|
|
5
5
|
webtap/filters.py,sha256=nphF2bFRbFtS2ue-CbV1uzKpuK3IYBbwjLeLhMDdLEk,11034
|
|
6
6
|
webtap/cdp/README.md,sha256=0TS0V_dRgRAzBqhddpXWD4S0YVi5wI4JgFJSll_KUBE,5660
|
|
7
7
|
webtap/cdp/__init__.py,sha256=c6NFG0XJnAa5GTe9MLr9mDZcLZqoTQN7A1cvvOfLcgY,453
|
|
@@ -28,6 +28,7 @@ webtap/commands/javascript.py,sha256=QpQdqqoQwwTyz1lpibZ92XKOL89scu_ndgSjkhaYuDk
|
|
|
28
28
|
webtap/commands/launch.py,sha256=iZDLundKlxKRLKf3Vz5at42-tp2f-Uj5wZf7fbhBfA0,2202
|
|
29
29
|
webtap/commands/navigation.py,sha256=Mapawp2AZTJQaws2uwlTgMUhqz7HlVTLxiZ06n_MQc0,6071
|
|
30
30
|
webtap/commands/network.py,sha256=hwZshGGdVsJ_9MFjOKJXT07I990JjZInw2LLnKXLQ5Y,2910
|
|
31
|
+
webtap/commands/server.py,sha256=LSs3l3Pb_vwmWRnYH-sA9JUPxBTQtRedjFQ4KvDaZK0,6032
|
|
31
32
|
webtap/commands/setup.py,sha256=dov1LaN50nAEMNIuBLSK7mcnwhfn9rtqdTopBm1-PhA,9648
|
|
32
33
|
webtap/services/README.md,sha256=rala_jtnNgSiQ1lFLM7x_UQ4SJZDceAm7dpkQMRTYaI,2346
|
|
33
34
|
webtap/services/__init__.py,sha256=IjFqu0Ak6D-r18aokcQMtenDV3fbelvfjTCejGv6CZ0,570
|
|
@@ -42,7 +43,7 @@ webtap/services/setup/desktop.py,sha256=fXwQa201W-s2mengm_dJZ9BigJopVrO9YFUQcW_T
|
|
|
42
43
|
webtap/services/setup/extension.py,sha256=OvTLuSi5u-kBAkqWAzfYt5lTNZrduXoCMZhFCuMisew,3318
|
|
43
44
|
webtap/services/setup/filters.py,sha256=lAPSLMH_KZQO-7bRkmURwzforx7C3SDrKEw2ZogN-Lo,3220
|
|
44
45
|
webtap/services/setup/platform.py,sha256=7yn-7LQFffgerWzWRtOG-yNEsR36ICThYUAu_N2FAso,4532
|
|
45
|
-
webtap_tool-0.
|
|
46
|
-
webtap_tool-0.
|
|
47
|
-
webtap_tool-0.
|
|
48
|
-
webtap_tool-0.
|
|
46
|
+
webtap_tool-0.3.0.dist-info/METADATA,sha256=jm3l2rpT1TBdGU8AU7NJYV7RgwpfzITuPyjh4Zb1_pk,17588
|
|
47
|
+
webtap_tool-0.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
48
|
+
webtap_tool-0.3.0.dist-info/entry_points.txt,sha256=iFe575I0CIb1MbfPt0oX2VYyY5gSU_dA551PKVR83TU,39
|
|
49
|
+
webtap_tool-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|