Chrome扩展:QuerySelector上的null参数错误在内容脚本上

发布于 2025-02-01 05:54:15 字数 389 浏览 3 评论 0原文

我正在创建一个镀铬扩展名,它将与Twitch Drops相互作用,并通知我是否准备好收集。我正在将内容脚本注入特定元素的类别,但它显示无法读取null的属性(读取'getAttribute')。 这是我的内容。JS代码:

var element = document.querySelector(".juerA");
var val = element.getAttribute('value');
console.log(val);

如果我在控制台上运行相同的代码,则可以正常运行。我尝试使用“ run_at”:“ document_end” ,但它不起作用。如果我将内容脚本的匹配与其他网页更改,则我还检查了扩展程序是否有效,并且可以正常工作。

I am creating a chrome extension that will interact with twitch drops and notify me if the drop is ready for collection. I am injecting a content script fetch attributes of a particular element by its class but it shows Cannot read properties of null (reading 'getAttribute').
Here is my content.js code:

var element = document.querySelector(".juerA");
var val = element.getAttribute('value');
console.log(val);

If I run the same code on the console, it works fine. I have tried using "run_at" : "document_end" but it doesn't work. I have also checked if the extension works if I change the matches of the content script with other web pages and it works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文