     window.location.href = window.location.origin
 
   toggleViewSource: ->
-    chrome.extension.sendMessage { handler: "getCurrentTabUrl" }, (url) ->
+    chrome.runtime.sendMessage { handler: "getCurrentTabUrl" }, (url) ->
       if (url.substr(0, 12) == "view-source:")
         url = url.substr(12, url.length - 12)
       else
         url = "view-source:" + url
-      chrome.extension.sendMessage({ handler: "openUrlInNewTab", url: url, selected: true })
+      chrome.runtime.sendMessage({ handler: "openUrlInNewTab", url: url, selected: true })
 
   copyCurrentUrl: ->
     # TODO(ilya): When the following bug is fixed, revisit this approach of sending back to the background
     # page to copy.
     # http://code.google.com/p/chromium/issues/detail?id=55188
-    chrome.extension.sendMessage { handler: "getCurrentTabUrl" }, (url) ->
-      chrome.extension.sendMessage { handler: "copyToClipboard", data: url }
+    chrome.runtime.sendMessage { handler: "getCurrentTabUrl" }, (url) ->
+      chrome.runtime.sendMessage { handler: "copyToClipboard", data: url }
 
     HUD.showForDuration("Yanked URL", 1000)
 

window.addEventListener("DOMContentLoaded", initializeOnDomReady)

window.onbeforeunload = ->
  chrome.extension.sendMessage(
    handler: "updateScrollPosition"
    scrollX: window.scrollX
    scrollY: window.scrollY)

  enterInsertModeIfElementIsFocused() if isEnabledForUrl

  # Tell the background page we're in the dom ready state.
  chrome.runtime.connect({ name: "domReady" })

# This is a little hacky but sometimes the size wasn't available on domReady?
registerFrameIfSizeAvailable = (is_top) ->
  if (innerWidth != undefined && innerWidth != 0 && innerHeight != undefined && innerHeight != 0)
    chrome.runtime.sendMessage(
      handler: "registerFrame"
      frameId: frameId
      area: innerWidth * innerHeight
