google-chrome-extension - 如何检查浏览器扩展内容脚本是否已加载到后台页面中包含的外部 iframe 上?
问题描述
假设我的扩展程序有一个后台页面,该页面注入了一个外部 iframe,该 iframe 又运行一个内容脚本,如下所示。你会建议我用什么机制来检查后台脚本接收到的消息是否onConnect
来自onMessage
后台页面中加载的内容脚本,而不是来自任何其他永恒网页?
背景.js
import browser from 'webextension-polyfill';
var iframe = document.createElement("iframe");
iframe.src = 'https://example.com/favicon.ico';
document.body.appendChild(iframe);
清单.json
{
"name": "My Extension",
"background": {
"scripts": ["background.js"],
"persistent": true
},
"manifest_version": 2,
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"content_scripts": [
{
"matches": ["https://example.com/favicon.ico"],
"js": ["content.js"],
"all_frames": true
}
],
"permissions": [
"*://example.com/*",
"webRequest",
"webRequestBlocking"
]
}
解决方案
推荐阅读
- jquery - 仅发送第一个输入值的输入字段数组
- regex - 如何排除前面字符与正则表达式中指定的字符不同的字符?
- visual-studio - 如何使用多个参数测试 Azure 函数
- android - 如何修复模拟器上的 apiAvailability.isGooglePlayServicesAvailable 行为不端
- mysql - PrestaShop 无缘无故地在 /tmp 中创建 #sql_ 文件
- typo3 - TYPO3 ConnectionPool 找到文件引用的uid后的文件并更新数据
- json - JQ:Bigint 数字精度
- java - AdMob 自定义事件插页式广告不显示
- javascript - 将 javascript 变量插入交易电子邮件中的 href 链接
- node.js - 如何防止模块在 NodeJS 中被加载到生产环境中?