Google chrome extension 未捕获类型错误:无法读取属性';选中';chrome.storage.get()中的空值

Google chrome extension 未捕获类型错误:无法读取属性';选中';chrome.storage.get()中的空值,google-chrome-extension,Google Chrome Extension,当我尝试将我的Google Chrome扩展加载到浏览器中时,我的options.js文件出现上述错误: 以下是我的选项.js: var email_addr = document.getElementById("email_addr"); var email_password = document.getElementById("email_password"); var registerButton = document.getElementById("register"); var ur

当我尝试将我的Google Chrome扩展加载到浏览器中时,我的options.js文件出现上述错误:

以下是我的选项.js:

var email_addr = document.getElementById("email_addr");
var email_password = document.getElementById("email_password");
var registerButton = document.getElementById("register");
var url = document.getElementById("url");
var port = document.getElementById("port");
var password = document.getElementById("password");
var ecs_mode = document.getElementById("ecs_mode");
var encrypt = document.getElementById("encrypt");
var include_content = document.getElementById("include_content");
var saveButton = document.getElementById("save");
debugger;
restore_settings();
  chrome.storage.sync.get({"emailAddr": email_addr.value, 
"emailPassword": email_password.value, 
"contentServerURL": url.value, 
"contentServerPort": port.value, 
"contentServerPassword": password.value,
"ecs_mode": ecs_mode.checked,
"encrypt": encrypt.checked,
"include_content": include_content.checked},
function() {
// Update status to let user know settings were saved.
var status = document.getElementById("status");
status.innerHTML = "Settings Saved.";
setTimeout(function() {
        status.innerHTML = "";
}, 750);
});

function register_addr() {
}

// Saves settings to chrome.storage.
function save_settings() {
  if (!password.value) return;

  chrome.storage.sync.set({"emailAddr": email_addr.value, 
"emailPassword": email_password.value, 
"contentServerURL": url.value, 
"contentServerPort": port.value, 
"contentServerPassword": password.value,
"ecs_mode": ecs_mode.checked,
"encrypt": encrypt.checked,
"include_content": include_content.checked}, 
function() {
  // Update status to let user know settings were saved.
var status = document.getElementById("status");
status.innerHTML = "Settings Saved.";
setTimeout(function() {
        status.innerHTML = "";
}, 750);
});
}

// Restores select box state to saved value from localStorage.
function restore_settings() {  
  chrome.storage.sync.get("emailAddr", function(val) {
email_addr.value = val.emailAddr;
});
  chrome.storage.sync.get("emailPassword", function(val) {
email_password.value = val.emailPassword;
});
  chrome.storage.sync.get("contentServerPassword", function(val) {
password.value = val.contentServerPassword;
});
  chrome.storage.sync.get("contentServerURL", function(val) {
url.value = val.contentServerURL;
});
  chrome.storage.sync.get("contentServerPort", function(val) {
port.value = val.contentServerPort;
});
  chrome.storage.sync.get("ecs_mode", function(val) {
ecs_mode.checked = val.ecs_mode;
});
  chrome.storage.sync.get("encrypt", function(val) {
encrypt.checked = val.encrypt;
});
  chrome.storage.sync.get("include_content", function(val) {
include_content.checked = val.include_content;
});
registerButton.disabled = false;
saveButton.disabled = false;
}

function ecs_mode_fn() {
if (ecs_mode.checked) {
  encrypt.disabled = false;
  include_content.disabled = false;
}
else {
  encrypt.disabled = true;
  include_content.disabled = true;
}
}

function toggleButton() {
if (email_addr.value.length == 0) {
    registerButton.disabled = true;
    saveButton.disabled = true;
}
else {
    registerButton.disabled = false;
    saveButton.disabled = false;
}
}

document.addEventListener('DOMContentReady', restore_settings);
if (document.querySelector('#save, #ecs_mode, #save, #restore, #register') != null)         {
document.querySelector('#ecs_mode').addEventListener('click', ecs_mode_fn);
document.querySelector('#save').addEventListener('click', save_settings);
document.querySelector('#restore').addEventListener('click', restore_settings);
document.querySelector('#email_addr').addEventListener('keyup', toggleButton);
document.querySelector('#register').addEventListener('click', register_addr);
}
options.html:

<html>
<head><title>ECS Extension Settings</title>
 <style type="text/css">
    body {
        width: 800px;
        height: 200px;
 }
</style>
</head>

<body>
<center><h1>ECS Content Server Settings</h1></center>
<div title="Enter your e-mail address and password here. The address can be a     regular Gmail address ('<someone>@gmail.com') or an e-mail address associated with a Google business account.">
<b>Your e-mail address:</b>
<input type="text" id="email_addr">
<b>Password:</b>
<input type="password" id="email_password">
<button id="register" disabled>Register</button>
</div>
<br>
After entering your e-mail address and password, press the <b>Register</b> button to register your address with the ChiaraMail content server. You will then be sent a registration confirmation e-mail containing a link. Select the link to show your content server password and enter the password in the <b>Content server password</b> field below.
<p>
<div title="The name and port number of the content server are fixed. Enter the password you were assigned during registration. You may change your password later at https://www.chiaramail.com/login.jsp">
<b>Content server URL:</b>
<input type="text" id="url" value="www.chiaramail.com" disabled>
<b>Content server port:</b>
<input type="text" id="port" value="443" size="4" disabled>
<b>Content server password:</b>
<input type="password" id="password" maxlength="8" size="8">
<p>
</div>
<div title="Check the 'Send as ECS' box if you want to send e-mail by default using the ECS technology. You will have the option of changing this setting when you compose your message.">
<b>Send as ECS: </b>
<input type="checkbox" id="ecs_mode" checked>
</div>
<div title="Check the 'Encrypt message' box if you want the message to be stored encrypted on the content server. You will have the option of changing this setting when you compose your message.">
<b>Encrypt message: </b>
<input type="checkbox" id="encrypt">
</div>
<div title="Check the 'Include content' box if you want the message content to be sent along with the mail headers (useful when sending to mixed recipients, some enabled for ECS and others who are not). You will have the option of changing this setting when you compose your message.">
<b>Include content: </b>
<input type="checkbox" id="include_content" checked>
</div>
<!--<div title="Select the 'Show ECS users' box to display message senders in magenta if the sender's e-mail address is registered with the ChiaraMail content server. This enables you to know which of your recipients are able to read ECS messages, but setting this option may adversely affect performance.">
<p>
<b>Show ECS users:</b>
<input type="checkbox" id="ecsusers" checked>-->
</div>
<br>
<div id="status"></div>
<div title="Press 'Save settings' to save your settings and 'Restore settings' to display them. Changes made to your account are propagated to all your devices and systems.">
<button id="save" disabled>Save settings</button>
<button id="restore">Restore settings</button>
</div>
<script src="options.js"></script>
</body>
</html>

我怀疑问题在于我编码chrome.storage.get()的方式,但我找不到API引用。不过,我很确定我正确地编写了对chrome.storage.get()的调用。我遗漏了什么?

事实证明,在更正丢失的UI元素后,我需要清除错误。我不明白谷歌为什么要求用户在重新加载扩展之前清除错误;重新加载时应将其清除。

chrome.storage API与此问题无关。您需要的是使用devtools来找出到底出了什么问题。Devtools是您的主要调试工具,可帮助您在几秒钟内解决此类问题。打开选项页面,右键单击内部,单击“检查”,切换到源面板并启用工具栏中的“暂停异常”按钮,然后在devtools中按F5重新加载页面。嗯…我在任何地方都找不到“暂停异常”按钮。它不在菜单中,它在面板本身中,请参阅。默认情况下,这些错误是为未打包的扩展收集的,您可以在中禁用它chrome://extensions 分机的详细信息页。@wOxxOm谢谢,完成了。
"name": "Envelope-Content Splitting (ECS) Support for Gmail",
"version": "1.0",
"manifest_version": 2,
"description": "Add ECS support for Gmail running in Chrome. This enables Gmail users who access their accounts via the Google Chrome browser to send and read ECS mail. Check out http://www.chiaramail.com for information about ECS and for links to other FREE ECS-enabled mail clients and extensions.",
"browser_action": {
"default_icon": {"19": "ecs_icon_19.png", "38": "ecs_icon_38.png"},
"default_title": "Press here to configure ECS settings",
"default_popup": "options.html"
},
"options_page": "options.html",
"icons": { "16": "ecs_icon_16.png", "48": "ecs_icon_48.png", "128":     "ecs_icon_128.png"},
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"run_at": "document_idle",
"matches": ["https://mail.google.com/mail/*"],
"js": ["updateContent.js", "colorHeaders.js", "renderContent.js", "sendOptions.js",     "base64.js", "jsaes.js"]
}
],
"permissions": ["tabs",
"activeTab",
"storage",
"https://mail.google.com/mail/*"],
"content_security_policy": "script-src 'self' https://www.chiaramail.com; object-src 'self'"
}