Index: tools/chrome_remote_control/chrome_remote_control/tab_runtime.py |
diff --git a/tools/chrome_remote_control/chrome_remote_control/tab_runtime.py b/tools/chrome_remote_control/chrome_remote_control/tab_runtime.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c78b123d1cf41d55a4ae38a786edb0c84798b176 |
--- /dev/null |
+++ b/tools/chrome_remote_control/chrome_remote_control/tab_runtime.py |
@@ -0,0 +1,41 @@ |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+class EvaluateException(Exception): |
+ pass |
+ |
+class TabRuntime(object): |
+ def __init__(self, inspector_backend): |
+ self._inspector_backend = inspector_backend |
+ self._inspector_backend.RegisterDomain( |
+ 'Runtime', |
+ self._OnNotification, |
+ self._OnClose) |
+ |
+ def _OnNotification(self, msg): |
+ pass |
+ |
+ def _OnClose(self): |
+ pass |
+ |
+ def Evaluate(self, expr): |
+ request = { |
+ "method": "Runtime.evaluate", |
+ "params": { |
+ "expression": expr, |
+ "returnByValue": True |
+ } |
+ } |
+ res = self._inspector_backend.SyncRequest(request) |
+ if "error" in res: |
+ raise EvaluateException(res["error"]["message"]) |
+ |
+ if res["result"]["wasThrown"]: |
+ # TODO(nduca): propagate stacks from javascript up to the python |
+ # exception. |
+ raise EvaluateException(res["result"]["result"]["description"]) |
+ if res["result"]["result"]["type"] == 'undefined': |
+ return None |
+ return res["result"]["result"]["value"] |
+ |