     .catch -> null
 
     @swValidation = @ready.then =>
-      @sw.call 'ping', null, {timeout: @handshakeTimeout}
+      @sw?.call 'ping', null, {timeout: @handshakeTimeout}
     .then (registeredMethods) =>
       @parentsRegisteredMethods = @parentsRegisteredMethods.concat(
         registeredMethods

        readyTimeout = setTimeout resolve, SW_CONNECT_TIMEOUT_MS

        navigator.serviceWorker.ready
        .catch -> null
        .then (registration) =>
          worker = registration?.active
          if worker

RPCClient = require './rpc_client'

DEFAULT_HANDSHAKE_TIMEOUT_MS = 10000 # 10 seconds
SW_CONNECT_TIMEOUT_MS = 5000 # 5s

selfWindow = if window? then window else self

