Google chrome extension Chrome扩展中的页面加载事件

Google chrome extension Chrome扩展中的页面加载事件,google-chrome-extension,Google Chrome Extension,我想在完全加载chrome浏览器页面时检查其内容中的一些值 那样 if(document.body.innerText.indexOf("Cat") !=-1) 我在哪里和什么时候可以结账?请给我一个明确的例子 我读了一些关于“Background.html”和“Content script”的东西,但我不能在“run\u at”:“document\u idle”(默认设置)中执行这些操作,并将代码放在Content script文件中。然后,当页面准备就绪时,脚本将运行 如果要从后台页面检

我想在完全加载chrome浏览器页面时检查其内容中的一些值 那样

if(document.body.innerText.indexOf("Cat") !=-1)
我在哪里和什么时候可以结账?请给我一个明确的例子 我读了一些关于“Background.html”和“Content script”的东西,但我不能在“run\u at”:“document\u idle”(默认设置)中执行这些操作,并将代码放在Content script文件中。然后,当页面准备就绪时,脚本将运行

如果要从后台页面检测页面是否已完全加载,请使用事件并执行任何操作,例如调用以执行内容脚本。如果URL列表是动态的,或者无法使用语法描述URL模式,则此方法可能比前一种方法更有用

chrome.webNavigation.onCompleted.addListener(函数(详细信息)){
chrome.tabs.executeScript(details.tabId{
代码:“if(document.body.innerText.indexOf(“Cat”)!=-1{”+
“警报(“找不到猫!”);”+
' }'
});
}, {
网址:[{
//在example.com、example.net上运行,但也在example.foo.com上运行
主机包含:'.example'
}],
});
必须在中设置
webNavigation
和主机权限,例如:


谢谢Rob W,但是我在check语句之后有很多代码,我不能在“code:”“我可以调用函数吗?”@user1291538您可以将它放在扩展名内的一个单独文件中,并使用
文件:'nameoffile.js'
而不是
“code:”…
-另请参阅。
{
  "name": "Test",
  "version": "1.0",
  "background": { "scripts": ["background.js"] },
  "permissions": [ "webNavigation", "*://*/*" ],
  "manifest_version": 2
}