This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdevtools-inject.py
68 lines (60 loc) · 1.98 KB
/
devtools-inject.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from requests import get
from websocket import create_connection
from json import dumps, loads
from sys import argv
from os import listdir, path
from time import sleep
BASE_ADDRESS = "http://localhost:8080"
class Tab:
def __init__(self, res) -> None:
self.title = res["title"]
self.id = res["id"]
self.ws_url = res["webSocketDebuggerUrl"]
def evaluate_js(self, js):
ws = create_connection(self.ws_url)
ws.send(dumps({
"id": 1,
"method": "Runtime.evaluate",
"params": {
"expression": js,
"userGesture": True
}
}))
response = ws.recv()
ws.close()
return response
def __str__(self):
return self.title
def __repr__(self):
return self.title
def get_tabs():
while True:
try:
res = get("{}/json".format(BASE_ADDRESS)).json()
return [Tab(i) for i in res]
except Exception as e:
print("Could not fetch tabs from Steam CEF instance. Are you sure steam is running ?")
print(e)
print("Retrying in 5 seconds")
sleep(5)
def main():
tabs = get_tabs()
files = listdir(argv[1])
for file in files:
fp = open(path.join(argv[1], file, "main.js"), "r")
cfg = loads(fp.readline()[2:])
if not cfg.get("enabled"):
continue
print("Loading {} with cfg {}".format(file, cfg))
while True:
tab = next((i for i in tabs if i.title == cfg["target_tab"]), None)
if tab:
print("Found tab {} with ID {}. Injecting JS...".format(tab.title, tab.id))
print(tab.evaluate_js(fp.read()))
break
else:
print("Target tab {} not found in fetched tabs. Refreshing tabs and retrying in 5 seconds".format(cfg["target_tab"]))
tabs = get_tabs()
sleep(5)
if __name__ == "__main__":
main()