title: Chrome Extension IME sample error
body: <p>I am attempting to learn how to build a Chrome extension.  So this question has as much to do with that process, as the code itself.</p>
  
  <p>I downloaded the sample code from here: <a href="https://developer.chrome.com/extensions/samples#search:.ime" rel="nofollow">https://developer.chrome.com/extensions/samples#search:.ime</a> (code below)</p>
  
  <p>Then I browsed to chrome://extensions, enabled developer mode, and clicked load unpacked extension - and selected the directory with the below 2 files.</p>
  
  <p>Loading the extension reports an error on line 9 of main.js (console.log("Initializing IME");) "anonymous function".</p>
  
  <ol>
  <li><strong>Why does the code produce an error?</strong></li>
  <li><p><strong>Did I load the extension correctly?</strong>  (it doesn't appear to be activated, possibly due to the error?)</p></li>
  <li><p>I can resolve the error by commenting out the offending line, but the extension still appears not to be activated.  <strong>How do I activate it?</strong>  (am I missing something?)</p></li>
  </ol>
  
  <p>manifest.json:</p>
  
  <pre><code>{
   "name": "Test IME",
   "version": "1.0",
   "manifest_version": 2,
   "description": "A simple IME that converts all keystrokes to upper case.",
   "background":  {
     "scripts": ["main.js"]
   }, 
   "permissions": [
     "input"
   ],
   "input_components": [
     {
       "name": "Test IME",
       "type": "ime",
       "id": "test",
       "description": "Test IME",  // A user visible description
       "language": "en-US",  // The primary language this IME is used for
       "layouts": ["us::eng"]  // The supported keyboard layouts for this IME
     }
   ] 
  }
  </code></pre>
  
  <p>main.js:</p>
  
  <pre><code>// Copyright 2013 The Chromium Authors. All rights reserved.
  // Use of this source code is governed by a BSD-style license that can be
  // found in the LICENSE file.
  
  var ime_api = chrome.input.ime;
  
  var context_id = -1;
  
  console.log("Initializing IME");
  
  ime_api.onFocus.addListener(function(context) {
    console.log('onFocus:' + context.contextID);
    context_id = context.contextID;
  });
  ime_api.onBlur.addListener(function(contextID) {
    console.log('onBlur:' + contextID);
    context_id = -1;
  });
  
  ime_api.onActivate.addListener(function(engineID) {
    console.log('onActivate:' + engineID);
  });
  ime_api.onDeactivated.addListener(function(engineID) {
    console.log('onDeactivated:' + engineID);
  });
  
  ime_api.onKeyEvent.addListener(
  function(engineID, keyData) {
    console.log('onKeyEvent:' + keyData.key + " context: " + context_id);
    if (keyData.type == "keydown" &amp;&amp; keyData.key.match(/^[a-z]$/)) {
      chrome.input.ime.commitText({"contextID": context_id,
                                   "text": keyData.key.toUpperCase()});
      return true;
    }
  
    return false
  });
  </code></pre>