Create main.py
Browse files
main.py
CHANGED
|
@@ -1,19 +1,39 @@
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
-
import
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
-
|
| 6 |
-
# Remote browser server URL
|
| 7 |
-
REMOTE_BROWSER_API = "https://YOUR_REMOTE_BROWSER_SERVER_URL/command"
|
| 8 |
|
| 9 |
@app.route("/command", methods=["POST"])
|
| 10 |
def command():
|
| 11 |
data = request.json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
try:
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
except Exception as e:
|
| 16 |
return jsonify({"error": str(e)}), 500
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
if __name__ == "__main__":
|
| 19 |
app.run(host="0.0.0.0", port=5000)
|
|
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
+
from browser_controller import BrowserController
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
+
browser = BrowserController()
|
|
|
|
|
|
|
| 6 |
|
| 7 |
@app.route("/command", methods=["POST"])
|
| 8 |
def command():
|
| 9 |
data = request.json
|
| 10 |
+
action = data.get("action")
|
| 11 |
+
selector = data.get("selector")
|
| 12 |
+
value = data.get("value")
|
| 13 |
+
pixels = data.get("pixels", 0)
|
| 14 |
+
url = data.get("url")
|
| 15 |
+
|
| 16 |
try:
|
| 17 |
+
if action == "navigate" and url:
|
| 18 |
+
result = browser.navigate(url)
|
| 19 |
+
elif action == "click" and selector:
|
| 20 |
+
result = browser.click(selector)
|
| 21 |
+
elif action == "type" and selector and value:
|
| 22 |
+
result = browser.type_text(selector, value)
|
| 23 |
+
elif action == "scroll":
|
| 24 |
+
result = browser.scroll(pixels)
|
| 25 |
+
else:
|
| 26 |
+
return jsonify({"error": "Invalid command"}), 400
|
| 27 |
+
|
| 28 |
+
return jsonify(result)
|
| 29 |
+
|
| 30 |
except Exception as e:
|
| 31 |
return jsonify({"error": str(e)}), 500
|
| 32 |
|
| 33 |
+
@app.route("/close", methods=["POST"])
|
| 34 |
+
def close_browser():
|
| 35 |
+
browser.close()
|
| 36 |
+
return jsonify({"status": "browser closed"})
|
| 37 |
+
|
| 38 |
if __name__ == "__main__":
|
| 39 |
app.run(host="0.0.0.0", port=5000)
|