该问题继续下面给出的链接。整个页面的源代码,包括铬扩展中的框架
Getting the source HTML of the current page from chrome extension
在上述URL中给出的答案顶部得到本标签的源代码。但是这并没有在源代码的iframe中获得源代码。
如何访问整个页面的源代码,包括chrome扩展中的FRAMES?
该问题继续下面给出的链接。整个页面的源代码,包括铬扩展中的框架
Getting the source HTML of the current page from chrome extension
在上述URL中给出的答案顶部得到本标签的源代码。但是这并没有在源代码的iframe中获得源代码。
如何访问整个页面的源代码,包括chrome扩展中的FRAMES?
使用allFrames: true
参数chrome.tabs.executeScript将代码注入到所有帧中。回调函数将收到的结果的数组,所有的帧:
popup.js:
chrome.tabs.executeScript({
allFrames: true,
code: 'JSON.stringify({ \
url: location.href, \
html: document.documentElement.innerHTML \
})'
}, function(results) {
if (chrome.runtime.lastError || !results || !results.length) {
console.log("Some error occurred", chrome.runtime.lastError);
} else {
results.forEach(function(str, index) {
var info = JSON.parse(str);
console.log("Frame #%d | %s | %s",
index, info.url, info.html.substr(0, 200) + "...");
});
}
});
工作就像一个魅力。谢谢。为了避免混淆,在executeScript函数中添加可选的IntegerId参数 –
使用chrome。* API函数,不需要为* optional *参数指定'null'或'undefined'。这是一件非常好的事情。 – wOxxOm
有没有办法从数组中获取帧的url? –
欢迎堆栈溢出。我们很乐意帮助你。为了提高获得答案的机会,以下是一些提示:[我如何提出一个好问题?] –