我正在尝试学习如何构建一个Chrome扩展。因此,这个问题和代码本身一样,与这个过程有关。
我从这里下载了示例代码:https://developer.chrome.com/extensions/samples#search:.ime (下面的代码)
然后,我浏览了chrome:// extension,启用了开发人员模式,并单击load解压缩扩展--并选择了下面两个文件的目录。
加载扩展在main.js (console.log("Initializing“)的第9行报告了一个错误;)”匿名函数“。
manifest.json:
{
"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
}
]
}main.js:
// 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" && keyData.key.match(/^[a-z]$/)) {
chrome.input.ime.commitText({"contextID": context_id,
"text": keyData.key.toUpperCase()});
return true;
}
return false
});发布于 2016-06-01 21:04:30
好的,这里的问题是分机是一个IME (键盘)
还有一个额外的步骤来启用它。
设置--语言&输入设置
然后使用ctrl空间选择新的输入法。
一切正常运作。
PS -而“错误”毕竟不是一个错误。
https://stackoverflow.com/questions/37570834
复制相似问题