Index: tools/telemetry/telemetry/core/backends/chrome/inspector_runtime.py |
diff --git a/tools/telemetry/telemetry/core/backends/chrome/inspector_runtime.py b/tools/telemetry/telemetry/core/backends/chrome/inspector_runtime.py |
index 529d1287c68f32595622d9567256a5c7a550259d..3b8d19db7fbe812121f78628319c126157342d97 100644 |
--- a/tools/telemetry/telemetry/core/backends/chrome/inspector_runtime.py |
+++ b/tools/telemetry/telemetry/core/backends/chrome/inspector_runtime.py |
@@ -10,6 +10,7 @@ class InspectorRuntime(object): |
'Runtime', |
self._OnNotification, |
self._OnClose) |
+ self._contexts_enabled = False |
def _OnNotification(self, msg): |
pass |
@@ -17,25 +18,11 @@ class InspectorRuntime(object): |
def _OnClose(self): |
pass |
- def Execute(self, expr, timeout=60): |
- """Executes expr in javascript. Does not return the result. |
+ def Execute(self, expr, context_id, timeout): |
+ self.Evaluate(expr + '; 0;', context_id, timeout) |
- If the expression failed to evaluate, EvaluateException will be raised. |
- """ |
- self.Evaluate(expr + '; 0;', timeout) |
- |
- def Evaluate(self, expr, timeout=60): |
- """Evalutes expr in javascript and returns the JSONized result. |
- |
- Consider using Execute for cases where the result of the expression is not |
- needed. |
- |
- If evaluation throws in javascript, a python EvaluateException will |
- be raised. |
- |
- If the result of the evaluation cannot be JSONized, then an |
- EvaluationException will be raised. |
- """ |
+ def Evaluate(self, expr, context_id, timeout): |
+ self._EnableAllContexts(context_id) |
request = { |
'method': 'Runtime.evaluate', |
'params': { |
@@ -43,6 +30,8 @@ class InspectorRuntime(object): |
'returnByValue': True |
} |
} |
+ if context_id is not None: |
+ request['params']['contextId'] = context_id |
res = self._inspector_backend.SyncRequest(request, timeout) |
if 'error' in res: |
raise exceptions.EvaluateException(res['error']['message']) |
@@ -54,3 +43,10 @@ class InspectorRuntime(object): |
if res['result']['result']['type'] == 'undefined': |
return None |
return res['result']['result']['value'] |
+ |
+ def _EnableAllContexts(self, context_id): |
+ """Allow access to iframes as necessary.""" |
+ if context_id is not None and not self._contexts_enabled: |
+ self._inspector_backend.SyncRequest({'method': 'Runtime.enable'}, |
+ timeout=30) |
+ self._contexts_enabled = True |