您的位置:首页 > 房产 > 建筑 > edge 插件 iframe 读取

edge 插件 iframe 读取

2024/10/5 20:17:17 来源:https://blog.csdn.net/glc22/article/details/142354776  浏览:    关键词:edge 插件 iframe 读取

当前页面里的iframe 加载的网页没有注入到,无法读取 iframe里的节点内容

  1. 使用all_frames选项: 在你的content_scripts配置中,添加all_frames: true,这样可以确保脚本注入到所有的iframe中。

    "content_scripts": [{"matches": ["<all_urls>"],"js": ["content_hook.js"],"run_at": "document_start","all_frames": true},{"matches": ["<all_urls>"], "js": ["js/pako.min.js","js/utils.js", "js/coockie.js", "js/youtub.js", "content.js"],"run_at": "document_start","all_frames": true}
    ]
    
  2. 动态注入脚本: 你可以在background.js中监听webNavigation事件,并动态注入脚本到iframe中。

    chrome.webNavigation.onCompleted.addListener(function(details) {chrome.scripting.executeScript({target: {tabId: details.tabId, frameIds: [details.frameId]},files: ['content_hook.js']});
    }, {url: [{urlMatches: '<all_urls>'}]});
    
  3. 使用chrome.webRequest API: 你可以使用chrome.webRequest API来监听iframe的加载,并注入脚本。

    chrome.webRequest.onCompleted.addListener(function(details) {chrome.scripting.executeScript({target: {tabId: details.tabId, frameIds: [details.frameId]},files: ['content_hook.js']});
    }, {urls: ["<all_urls>"], types: ["sub_frame"]});
    

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com