-
Notifications
You must be signed in to change notification settings - Fork 3
/
runner-chrome.py
32 lines (26 loc) · 930 Bytes
/
runner-chrome.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
import chrome_remote_shell, re, time
class runner:
def __init__(self, port, site):
self.shell=chrome_remote_shell.open(port=port)
self.site = site
tabs = self.shell.request('DevToolsService', command='list_tabs')['data']
self.tabs = []
for (id, addr) in tabs:
if re.match('^http://(www\.)?'+site+'.*$', addr):
self.tabs.append(id)
def run(self, js):
for tab in self.tabs:
self.shell.request('V8Debugger', destination=tab, command='evaluate_javascript', data=js)
def runonce(self, js):
for tab in self.tabs:
self.shell.request('V8Debugger', destination=tab, command='evaluate_javascript', data=js)
break
def refresh(self):
self.run("window.location='http://www."+self.site+"/';");
# Let it reload and kill off alerts
time.sleep(0.5)
self.run("window.alert = alert = function(){};");
if __name__ == "__main__":
r = runner(9222, 'smokoo.co.za')
r.refresh()
r.run('alert("rawr");')