Exemplo n.º 1
0
    def SyncRequest(self, req, timeout=10):
        self._Connect()
        # TODO(nduca): Listen to the timeout argument
        # pylint: disable=W0613
        self._SetTimeout(timeout)
        self.SendAndIgnoreResponse(req)

        while True:
            try:
                data = self._socket.recv()
            except (socket.error, websocket.WebSocketException):
                if self._browser_backend.tab_list_backend.DoesDebuggerUrlExist(
                        self._debugger_url):
                    raise util.TimeoutException(
                        'Timed out waiting for reply. This is unusual.')
                raise exceptions.TabCrashException(sys.exc_info()[1])

            res = json.loads(data)
            logging.debug('got [%s]', data)
            if 'method' in res:
                self._HandleNotification(res)
                continue

            if res['id'] != req['id']:
                logging.debug('Dropped reply: %s', json.dumps(res))
                continue
            return res
Exemplo n.º 2
0
    def SyncRequest(self, req, timeout=10):
        self._Connect()
        self._SetTimeout(timeout)
        self.SendAndIgnoreResponse(req)

        while True:
            try:
                start_time = time.time()
                data = self._socket.recv()
            except (socket.error, websocket.WebSocketException):
                if self._browser_backend.tab_list_backend.DoesDebuggerUrlExist(
                        self._debugger_url):
                    elapsed_time = time.time() - start_time
                    raise util.TimeoutException(
                        'Received a socket error in the browser connection and the tab '
                        'still exists, assuming it timed out. '
                        'Timeout=%ds Elapsed=%ds Error=%s' %
                        (timeout, elapsed_time, sys.exc_info()[1]))
                raise exceptions.TabCrashException(
                    'Received a socket error in the browser connection and the tab no '
                    'longer exists, assuming it crashed. Error=%s' %
                    sys.exc_info()[1])

            res = json.loads(data)
            logging.debug('got [%s]', data)
            if 'method' in res:
                self._HandleNotification(res)
                continue

            if 'id' not in res or res['id'] != req['id']:
                logging.debug('Dropped reply: %s', json.dumps(res))
                continue
            return res
Exemplo n.º 3
0
    def __init__(self, browser_backend, context, timeout=60):
        super(InspectorBackend, self).__init__(self._HandleNotification,
                                               self._HandleError)

        self._browser_backend = browser_backend
        self._context = context
        self._domain_handlers = {}

        logging.debug('InspectorBackend._Connect() to %s', self.debugger_url)
        try:
            self.Connect(self.debugger_url)
        except (websocket.WebSocketException, util.TimeoutException):
            err_msg = sys.exc_info()[1]
            if not self._browser_backend.IsBrowserRunning():
                raise exceptions.BrowserGoneException(self.browser, err_msg)
            elif not self._browser_backend.HasBrowserFinishedLaunching():
                raise exceptions.BrowserConnectionGoneException(
                    self.browser, err_msg)
            else:
                raise exceptions.TabCrashException(self.browser, err_msg)

        self._console = inspector_console.InspectorConsole(self)
        self._memory = inspector_memory.InspectorMemory(self)
        self._page = inspector_page.InspectorPage(self, timeout=timeout)
        self._runtime = inspector_runtime.InspectorRuntime(self)
        self._timeline = inspector_timeline.InspectorTimeline(self)
        self._network = inspector_network.InspectorNetwork(self)
        self._timeline_model = None
 def _HandleError(self, elapsed_time):
     if self._IsInspectable():
         raise util.TimeoutException(
             'Received a socket error in the browser connection and the tab '
             'still exists, assuming it timed out. '
             'Elapsed=%ds Error=%s' % (elapsed_time, sys.exc_info()[1]))
     raise exceptions.TabCrashException(
         'Received a socket error in the browser connection and the tab no '
         'longer exists, assuming it crashed. Error=%s' % sys.exc_info()[1])
Exemplo n.º 5
0
    def _Connect(self):
        if self._socket:
            return
        try:
            self._socket = websocket.create_connection(self._debugger_url)
        except (websocket.WebSocketException):
            if self._browser_backend.IsBrowserRunning():
                raise exceptions.TabCrashException(sys.exc_info()[1])
            else:
                raise exceptions.BrowserGoneException()

        self._cur_socket_timeout = 0
        self._next_request_id = 0
Exemplo n.º 6
0
    def DispatchNotifications(self, timeout=10):
        self._Connect()
        self._SetTimeout(timeout)

        try:
            data = self._socket.recv()
        except (socket.error, websocket.WebSocketException):
            if self._browser_backend.tab_list_backend.DoesDebuggerUrlExist(
                    self._debugger_url):
                return
            raise exceptions.TabCrashException(sys.exc_info()[1])

        res = json.loads(data)
        logging.debug('got [%s]', data)
        if 'method' in res:
            self._HandleNotification(res)
Exemplo n.º 7
0
    def _Connect(self, timeout=10):
        assert not self._socket
        logging.debug('InspectorBackend._Connect() to %s' % self.debugger_url)
        try:
            self._socket = websocket.create_connection(self.debugger_url,
                                                       timeout=timeout)
        except (websocket.WebSocketException, util.TimeoutException):
            err_msg = sys.exc_info()[1]
            if not self._browser_backend.IsBrowserRunning():
                raise exceptions.BrowserGoneException(err_msg)
            elif not self._browser_backend.HasBrowserFinishedLaunching():
                raise exceptions.BrowserConnectionGoneException(err_msg)
            else:
                raise exceptions.TabCrashException(err_msg)

        self._cur_socket_timeout = 0
        self._next_request_id = 0
Exemplo n.º 8
0
    def _HandleNotification(self, res):
        if (res['method'] == 'Inspector.detached' and res.get(
                'params', {}).get('reason', '') == 'replaced_with_devtools'):
            self._WaitForInspectorToGoAwayAndReconnect()
            return
        if res['method'] == 'Inspector.targetCrashed':
            raise exceptions.TabCrashException()

        mname = res['method']
        dot_pos = mname.find('.')
        domain_name = mname[:dot_pos]
        if domain_name in self._domain_handlers:
            try:
                self._domain_handlers[domain_name][0](res)
            except Exception:
                import traceback
                traceback.print_exc()
        else:
            logging.debug('Unhandled inspector message: %s', res)
Exemplo n.º 9
0
 def _ReceiveJsonData(self, timeout):
     try:
         start_time = time.time()
         data = self._socket.recv()
     except (socket.error, websocket.WebSocketException):
         if self._IsInspectable():
             elapsed_time = time.time() - start_time
             raise util.TimeoutException(
                 'Received a socket error in the browser connection and the tab '
                 'still exists, assuming it timed out. '
                 'Timeout=%ds Elapsed=%ds Error=%s' %
                 (timeout, elapsed_time, sys.exc_info()[1]))
         raise exceptions.TabCrashException(
             'Received a socket error in the browser connection and the tab no '
             'longer exists, assuming it crashed. Error=%s' %
             sys.exc_info()[1])
     res = json.loads(data)
     logging.debug('got [%s]', data)
     return res