首页 > 解决方案 > 在运行教程中给出的代码后,按照 chrome 扩展教程得到“Uncaught SyntaxError:missing )”

问题描述

我一直在按照本教程在 Chrome 上进行扩展,但在我必须编写一个 JS 文件并编译它的步骤中遇到了困难。该代码已在教程中提供。

let changeColor = document.getElementById('changeColor');

  chrome.storage.sync.get('color', function(data) {
    changeColor.style.backgroundColor = data.color;
    changeColor.setAttribute('value', data.color);
  });

但是当我尝试重新加载扩展时,它给出了以下错误:

JS 错误

所以我查找了具有类似语法的chrome.storage API文档:

chrome.storage.sync.get(['key'], function(result) {
         console.log('Value currently is ' + result.key);
       });

我稍微修改了代码来调试它:

chrome.storage.sync.get(['color'], function(data) {
          console.log('Value currently is ' + data.color);
        });

我得到同样的错误:

在此处输入图像描述

有人可以解释我错过了什么吗?

标签: javascriptgoogle-chrome-extension

解决方案


好的,所以我在 5 天后重新加载了程序,现在它以某种方式工作,不知道它是如何工作的。


推荐阅读