我完全不知所措。我想從Chrome中的標籤中獲取html內容。從標籤頁獲取HTML內容
的manifest.json
{
"manifest_version": 2,
"name": "Test",is a test.",
"version": "1.0",
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"background": {
"scripts": ["main.js"],
"persistent": false
},
"permissions": [
"tabs",
"https://www.google.com"
]
}
main.js
var timerObj = new Timer({'interval':5000});
chrome.runtime.onStartup.addListener(timerObj.start(mainF));
function mainF() {
chrome.tabs.query({} ,function (tabs) {
for (var i = 0; i < tabs.length; i++) {
var url = tabs[i].url;
if (url != null) {
console.log(tabs[i].url);
//I want to get html source here
}
}
});
};
function Timer(obj){
最後一行function Timer(obj){
被截斷簡潔。 console.log(tabs[i].url);
用於測試。對於每個標籤,我希望獲得html源代碼。有了這個來源,我會解析標籤和其他內容。我見過其他資源提及sendMessage
和onMessage
,但我並沒有真正瞭解它。許多其他資源指代已棄用的sendRequest
和onRequest
。