chrome extension get source html 不是 currentPage
chrome extension get source html not currentPage
如何在 chrome 扩展中获取来源 https://google.com when I'm in http://example.com。
我读到:Getting the source HTML of the current page from chrome extension 但它只得到 html currentPage。
我需要从任何 url 获取 html 来源。
谢谢!
使用XMLHttpRequest下载访问url时服务器响应的任何内容。在某些网站上,它可能是一个带有脚本加载器的小页面,如果浏览器正常加载它,它稍后会呈现该页面。
要获得完全呈现的源或任意 url 的 DOM 树,您必须先将其加载到选项卡中。为了减少用户在固定选项卡中加载过程的注意力:
chrome.tabs.create({url: "https://google.com", pinned: true}, function(tab) {
.... wait for the tab to load, get the source
});
(不需要任何额外权限的最简单等待形式是定期检查从上述回调调用的 tab.status == "complete"
,否则使用 webNavigation.onCompleted for example or inject a content script 和 运行-普通的 "DOMContentLoaded" 或 "load" 事件处理程序)。
或者在 IFRAME
中加载页面,但有些网站 forbid 浏览器可以做到这一点。
如何在 chrome 扩展中获取来源 https://google.com when I'm in http://example.com。 我读到:Getting the source HTML of the current page from chrome extension 但它只得到 html currentPage。 我需要从任何 url 获取 html 来源。 谢谢!
使用XMLHttpRequest下载访问url时服务器响应的任何内容。在某些网站上,它可能是一个带有脚本加载器的小页面,如果浏览器正常加载它,它稍后会呈现该页面。
要获得完全呈现的源或任意 url 的 DOM 树,您必须先将其加载到选项卡中。为了减少用户在固定选项卡中加载过程的注意力:
chrome.tabs.create({url: "https://google.com", pinned: true}, function(tab) { .... wait for the tab to load, get the source });
(不需要任何额外权限的最简单等待形式是定期检查从上述回调调用的
tab.status == "complete"
,否则使用 webNavigation.onCompleted for example or inject a content script 和 运行-普通的 "DOMContentLoaded" 或 "load" 事件处理程序)。或者在
IFRAME
中加载页面,但有些网站 forbid 浏览器可以做到这一点。