File size: 1,134 Bytes
49fdb76
11e1e38
49fdb76
 
11e1e38
49fdb76
 
 
 
11e1e38
 
 
 
 
 
49fdb76
11e1e38
 
 
 
 
 
 
 
 
 
 
 
 
49fdb76
 
 
11e1e38
 
 
 
 
49fdb76
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask, request, jsonify
from browser_controller import BrowserController

app = Flask(__name__)
browser = BrowserController()

@app.route("/command", methods=["POST"])
def command():
    data = request.json
    action = data.get("action")
    selector = data.get("selector")
    value = data.get("value")
    pixels = data.get("pixels", 0)
    url = data.get("url")

    try:
        if action == "navigate" and url:
            result = browser.navigate(url)
        elif action == "click" and selector:
            result = browser.click(selector)
        elif action == "type" and selector and value:
            result = browser.type_text(selector, value)
        elif action == "scroll":
            result = browser.scroll(pixels)
        else:
            return jsonify({"error": "Invalid command"}), 400

        return jsonify(result)

    except Exception as e:
        return jsonify({"error": str(e)}), 500

@app.route("/close", methods=["POST"])
def close_browser():
    browser.close()
    return jsonify({"status": "browser closed"})

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)