简体   繁体   English

chrome.storage.sync 未定义错误

[英]chrome.storage.sync undefined error

I'm writing a simple extension and need to save user blacklisted keywords.我正在编写一个简单的扩展程序,需要保存用户列入黑名单的关键字。 I'm using the options_page for chrome to ask users for input, and save those words to the storage to be used later.我正在使用 chrome 的 options_page 来询问用户输入,并将这些词保存到存储中以备后用。 However, when I press 'save', I get the error Uncaught TypeError: Cannot read property 'sync' of undefined , but I followed the instructions in the chrome extension documentation.但是,当我按“保存”时,出现错误Uncaught TypeError: Cannot read property 'sync' of undefined ,但我遵循了 chrome 扩展文档中的说明。 I added "permissions": ["storage"] to the manifest.json file, and reloaded the extension and options page multiple times, yet I still get the same error.我将"permissions": ["storage"]到 manifest.json 文件,并多次重新加载扩展和选项页面,但我仍然遇到相同的错误。 Here's my javascript code:这是我的 javascript 代码:

var save_options = function() {
  var blacklistWords = document.getElementById('word').value;
  chrome.storage.sync.set({'blacklistWords': blacklistWords}, function() {
    // Update status to let user know options were saved.
    alert("saved");
  });
};

document.getElementById('save').addEventListener('click', save_options);

I would really appreciate it if someone could help me figure this out.如果有人能帮我解决这个问题,我将不胜感激。

Your application needs permissions to read/write sync storage.您的应用程序需要读取/写入同步存储的权限。

"permissions": [
  "storage",
],

每当您更新manifest.json文件时,始终重新加载扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM