Javascript 整个页面的源代码,包括chrome扩展中的框架
这个问题是下面给出的链接的继续 上面URL中给出的最上面的答案获取当前选项卡的源代码。但这并不能在源代码的iframe中获取源代码Javascript 整个页面的源代码,包括chrome扩展中的框架,javascript,google-chrome-extension,Javascript,Google Chrome Extension,这个问题是下面给出的链接的继续 上面URL中给出的最上面的答案获取当前选项卡的源代码。但这并不能在源代码的iframe中获取源代码 如何访问包含chrome extensions中框架的整个页面的源代码?使用的allFrames:true参数将代码注入所有框架。回调函数将接收一个数组,其中包含所有帧的结果: popup.js: chrome.tabs.executeScript({ allFrames: true, code: 'JSON.stringify({ \
如何访问包含chrome extensions中框架的整个页面的源代码?使用的
allFrames:true
参数将代码注入所有框架。回调函数将接收一个数组,其中包含所有帧的结果:
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) + "...");
});
}
});
欢迎来到堆栈溢出。我们很乐意帮助你。为了提高你得到答案的机会,这里有一些建议:像魅力一样工作。谢谢为了避免混淆,在带有chrome.*API函数的executeScript函数中添加可选IntegerId参数,无需为可选参数指定
null
或undefined
。这是一件非常好的事情。有没有办法从数组中获取帧的url?