我需要在iframe标签内听取更改。主页面不会更改,只有iframe内容。
iframe页面有表单,当点击某些按钮类型提交时,表单会调用该操作并仅在iframe内更改页面。
我接下来探测,但只适用于文档主页,只有主页文档侦听DOM更改,而不是内部iframe。
webdriver-manager update
webdriver-manager start
答案 0 :(得分:1)
我找到了一个解决方案,使用Google Extensions API我只使用内容脚本和后台页面之间的通信,然后每次更改都在网页中进行,后台页面向内容脚本发送一条消息,然后重新加载再次使用内容脚本,让我评估网页中我需要的内容。背景页面对我来说是最好的解决方案,因为它始终处于活动状态。
背景页
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {action: "doit"}, function(response) {});
});
}
});
内容脚本
chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) {
if (msg.action == 'doit') {
analize_with_content_script();
}
});
注意 analize_with_content_script()是从后台页面接收消息后触发的功能。
请记住后台页面需要在清单文件中声明。