 
     @api.once 'connect', =>
       @isActive = true
-      @api.debugger.enable(null, (err, result)->
-        debug('enabled returned', err, result)
-        if(err) then console.error err
-        else debug('debugger enabled')
-      )
-      @api.page.getResourceTree(null, (err, result)->
-        debug('getResourceTree returned!', err, result)
-      )
+      
+      debuggerEnabledPromise = q.all [
+        q.ninvoke @api.debugger, 'enable', null
+        q.ninvoke @api.page, 'getResourceTree', null
+      ]
       
     @api.once 'close', => @close()
 

    if @isActive then throw new Error('Already connected.')
    @onPause ?= ->
    @onResume ?= ->

    debug('starting debugger', wsUrl)
    # the current list of breakpoints is from before this

    )
    
    @api.on 'scriptParsed', (scriptObject)=>@addScript(scriptObject)

    debuggerEnabledPromise


  close: ->
