Uncaught TypeError: Невозможно прочитать свойство 'флажок' со значением null из chrome.storage.get () - PullRequest
0 голосов
/ 08 ноября 2019

Когда я пытаюсь загрузить свое расширение Google Chrome в браузер, я получаю вышеуказанную ошибку для моего файла options.js:

enter image description here

Здесьмои файлы options.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>

и manifest.json:

"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'"
}

Я подозреваю, что проблема заключается в способеЯ кодировал chrome.storage.get (), но не смог найти ссылку на API, , только пример того, как его назвать . Я почти уверен, что правильно закодировал вызов chrome.storage.get (). Чего мне не хватает?

1 Ответ

0 голосов
/ 08 ноября 2019

Оказывается, мне нужно было очистить ошибки после исправления отсутствующего элемента интерфейса. Я не понимаю, почему Google требует, чтобы пользователи очищали ошибки перед перезагрузкой расширения;перезагрузка должна очистить их.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...