| Index: tools/telemetry/telemetry/core/backends/chrome/inspector_page.py
|
| diff --git a/tools/telemetry/telemetry/core/backends/chrome/inspector_page.py b/tools/telemetry/telemetry/core/backends/chrome/inspector_page.py
|
| index e1071277802eff89535bfb2e8d6b0d3353914218..8c4c6fe899bde6d376c99eab406b652c35a1de4f 100644
|
| --- a/tools/telemetry/telemetry/core/backends/chrome/inspector_page.py
|
| +++ b/tools/telemetry/telemetry/core/backends/chrome/inspector_page.py
|
| @@ -15,12 +15,8 @@
|
| 'Page',
|
| self._OnNotification,
|
| self._OnClose)
|
| -
|
| - # Turn on notifications. We need them to get the Page.frameNavigated event.
|
| - self._EnablePageNotifications()
|
| self._navigation_pending = False
|
| self._navigation_url = ""
|
| - self._script_to_evaluate_on_commit = None
|
|
|
| def _OnNotification(self, msg):
|
| logging.debug('Notification: %s', json.dumps(msg, indent=2))
|
| @@ -36,36 +32,16 @@
|
| def _OnClose(self):
|
| pass
|
|
|
| - def _SetScriptToEvaluateOnCommit(self, source):
|
| - existing_source = (self._script_to_evaluate_on_commit and
|
| - self._script_to_evaluate_on_commit['source'])
|
| - if source == existing_source:
|
| - return
|
| - if existing_source:
|
| - request = {
|
| - 'method': 'Page.removeScriptToEvaluateOnLoad',
|
| - 'params': {
|
| - 'identifier': self._script_to_evaluate_on_commit['id'],
|
| - }
|
| - }
|
| - self._inspector_backend.SyncRequest(request)
|
| - self._script_to_evaluate_on_commit = None
|
| - if source:
|
| - request = {
|
| - 'method': 'Page.addScriptToEvaluateOnLoad',
|
| - 'params': {
|
| - 'scriptSource': source,
|
| - }
|
| - }
|
| - res = self._inspector_backend.SyncRequest(request)
|
| - self._script_to_evaluate_on_commit = {
|
| - 'id': res['result']['identifier'],
|
| - 'source': source
|
| - }
|
| -
|
| - def _EnablePageNotifications(self, timeout=60):
|
| + def _EnablePageNotifications(self, timeout):
|
| request = {
|
| 'method': 'Page.enable'
|
| + }
|
| + res = self._inspector_backend.SyncRequest(request, timeout)
|
| + assert len(res['result'].keys()) == 0
|
| +
|
| + def _DisablePageNotifications(self, timeout):
|
| + request = {
|
| + 'method': 'Page.disable'
|
| }
|
| res = self._inspector_backend.SyncRequest(request, timeout)
|
| assert len(res['result'].keys()) == 0
|
| @@ -79,15 +55,19 @@
|
| start_time = time.time()
|
| remaining_time = timeout
|
|
|
| - action_function()
|
| - self._navigation_pending = True
|
| try:
|
| - while self._navigation_pending and remaining_time > 0:
|
| - remaining_time = max(timeout - (time.time() - start_time), 0.0)
|
| - self._inspector_backend.DispatchNotifications(remaining_time)
|
| + self._EnablePageNotifications(remaining_time)
|
| + try:
|
| + action_function()
|
| + self._navigation_pending = True
|
| + while self._navigation_pending and remaining_time > 0:
|
| + remaining_time = max(timeout - (time.time() - start_time), 0.0)
|
| + self._inspector_backend.DispatchNotifications(remaining_time)
|
| + finally:
|
| + self._DisablePageNotifications(remaining_time)
|
| except util.TimeoutException:
|
| - # Since we pass remaining_time to DispatchNotifications, we need to
|
| - # list the full timeout time in this message.
|
| + # Since we pass remaining_time as timeout to all of the calls in this,
|
| + # method, we need to list the full timeout time in this message.
|
| raise util.TimeoutException('Timed out while waiting %ds for navigation. '
|
| 'Error=%s' % (timeout, sys.exc_info()[1]))
|
|
|
| @@ -100,7 +80,14 @@
|
| """
|
|
|
| def DoNavigate():
|
| - self._SetScriptToEvaluateOnCommit(script_to_evaluate_on_commit)
|
| + if script_to_evaluate_on_commit:
|
| + request = {
|
| + 'method': 'Page.addScriptToEvaluateOnLoad',
|
| + 'params': {
|
| + 'scriptSource': script_to_evaluate_on_commit,
|
| + }
|
| + }
|
| + self._inspector_backend.SyncRequest(request)
|
| # Navigate the page. However, there seems to be a bug in chrome devtools
|
| # protocol where the request id for this event gets held on the browser
|
| # side pretty much indefinitely.
|
|
|