javascript - Chrome的内容脚本默认不允许添加EventListeners?
问题描述
为了清楚起见,我阅读了多个类似的问题
1 2 3 4 5等
,它们都与我的无关。
据我了解,WebAPI内容脚本即使在隔离环境中运行,仍然可以操作页面的 DOM 并添加 EventListener,至少 Developer.Chrome 和 MDN 是这么说的。但是,我遇到的情况似乎不是真的。
这是一个示例扩展:
清单.json
{
"manifest_version": 2,
"name": "Foo",
"version": "0",
"permissions":
[
"storage",
"https://steamcommunity.com/*"
],
"content_scripts":
[ {
"matches": ["*://steamcommunity.com/groups/*"],
"js": ["content.js"],
"run_at": "document_idle",
"all_frames": true
} ]
}
内容.js
'use strict';
const butArea = document.querySelector(".grouppage_join_area");
function queueGroup()
{
alert('yay!');
}
if (butArea)
{
butArea.addEventListener("click", queueGroup, false);
}
加载解压并转到https://steamcommunity.com/groups/SteamClientBeta。点击他按钮,没有警报。通过控制台手动添加 eventListener ,它只是 werks。我也尝试click/onclick
了属性,但结果相同。
是的,我可以将我的代码注入页面,这里没有问题,但我真的不想这样做,因为它应该按原样工作,不是吗?否则 - 为什么不,我错过了什么?
解决方案
推荐阅读
- excel - 将数据从计划中提取到指定的部门工作表
- sql - 加入多列时,匹配列的顺序是否重要?
- angular - Angularfire 项目的 Google Cloud Build 超时
- drupal - 向注册用户显示他们已经提交了哪些网络表单
- pandas - 熊猫解析周数
- mysql - 如何在 mysql 中找到 LEAST() 使用的列?
- mapping - 如何在 APL 中使用 rank 运算符而不是 each
- django - 序列化器与视图通过外键字段检索对象
- python - 调整 PIL 图像大小:ValueError:未知重采样过滤器
- scala - 根据条件获取列表中的更新元组值