未捕获的类型错误:无法读取未定义的属性“查询”

时间:2021-06-20 15:02:29

标签: javascript google-chrome-extension typeerror

我的后台更改器 Chrome 扩展程序在控制台中收到此错误消息。我究竟做错了什么?任何帮助将不胜感激。下面列出了代码。

未捕获的类型错误:无法读取未定义的属性“查询” 在injectCSS (popup.js:26) 在 HTMLInputElement。 (popup.js:8)

const colorEl = document.getElementById('color-changer');

const rotateEl = document.getElementById('rotate');

const rotate3DEl = document.getElementById('rotate3d');

colorEl.addEventListener('input', () => {
  injectCSS(`body {
    background-color: ${colorEl.value}!important;
   }`);
});

rotateEl.addEventListener('input', () => {
  injectCSS(`body {
      transform: rotate(${rotateEl.value}deg)!important;
  }`);
});

rotate3DEl.addEventListener('input', () => {
  injectCSS(`body {
        transform: rotate3d(1,1,1,${rotate3DEl.value}deg)!important;
    }`);
});

   function injectCSS(css) {
  chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => {
    if (!tab) return;
    chrome.scripting.insertCSS({
       css,
      target: { tabId: tab.id },
    });
  });

}

0 个答案:

没有答案