在iFrame中注入内容脚本,但不在原始网站上

在iFrame中注入内容脚本,但不在原始网站上,iframe,google-chrome-extension,content-script,Iframe,Google Chrome Extension,Content Script,我有一个扩展,它使用iFrame将网站嵌入其中,我想在其中插入一个内容脚本来修改框架内的页面,我已经使用以下方法实现了这一点: "content_scripts": [{ "matches": ["http://website/*"], "js": ["js/jquery/jquery-3.2.1.min.js", "src/myScriptToInject.js"], "all_frames": true, "run_at": "document_start"

我有一个扩展,它使用iFrame将网站嵌入其中,我想在其中插入一个内容脚本来修改框架内的页面,我已经使用以下方法实现了这一点:

"content_scripts": [{
    "matches": ["http://website/*"],
    "js": ["js/jquery/jquery-3.2.1.min.js", "src/myScriptToInject.js"],
    "all_frames": true,
    "run_at": "document_start"
}],
它按预期工作,但问题是,如果我现在转到原始网站,它会自然地将我的脚本注入其中,使其完全崩溃

所以我尝试使用
chrome.tabs.executeScript(tab.id,{allFrames:true,runAt:'document_start',file:'src/myScriptToInject.js'})但问题是,如果我理解正确,出于“安全原因”,我无法在chrome扩展中插入脚本


有什么我没有想到的方法或技巧对我有帮助吗?

检查内容脚本中的
if(window!=top)
,看看它是否在iframe中,否则不要处理。哇,太简单了,非常感谢。