Google chrome extension document.querySelector对Chrome扩展中的web可访问资源具有过时的关闭?

Google chrome extension document.querySelector对Chrome扩展中的web可访问资源具有过时的关闭?,google-chrome-extension,Google Chrome Extension,对于我的Chrome扩展,我通过iframe将一个HTML页面插入DOM 在我的内容脚本中: const contentElem = document.createElement('iframe'); contentElem.src = chrome.runtime.getURL('popup.html'); containerElem.shadowRoot?.appendChild(contentElem); HTML页面popup.HTML加载JavaScript文件: <scrip

对于我的Chrome扩展,我通过iframe将一个HTML页面插入DOM

在我的内容脚本中:

const contentElem = document.createElement('iframe');
contentElem.src = chrome.runtime.getURL('popup.html');
containerElem.shadowRoot?.appendChild(contentElem);
HTML页面
popup.HTML
加载JavaScript文件:

<script type="module" src="popup.js"></script>

问题是有一个过时的值。当主体的类列表被修改(由
popup.js
中的其他代码修改)后,它仍然会记录与页面加载时相同的类列表。

classList不是一个原始值,因此它的预览是在devtools初次运行时生成的,而只有在console中展开该值时,才会显示真正的内容。更多信息:
window.onload = async function() {
  document.getElementById('btn')?.addEventListener('click', () => {
    console.log(document.querySelector('body'));
    console.log(document.querySelector('body')?.classList);
  });
}