-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathruntime.py
More file actions
28 lines (21 loc) · 757 Bytes
/
Copy pathruntime.py
File metadata and controls
28 lines (21 loc) · 757 Bytes
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
import json
class Runtime(object):
command_id = 0
def __init__(self, ws):
self.ws = ws
self.enable_runtime()
@property
def next_command_id(self):
self.command_id += 1
return self.command_id
def enable_runtime(self):
self.call_command(method='Runtime.enable')
print('Enabled Runtime.')
# def evaluate(self, expression):
# params = {"expression": expression}
# res = self.call_command(method='Runtime.evaluate', params=params)
# Not async
def call_command(self, method, params={}, callback=None):
msg = {'id': self.next_command_id, 'method': method, 'params': params}
self.ws.send(json.dumps(msg))
return json.loads(self.ws.recv())