以前はdocument.body.outerHTML
タブから html を取得していましたが、それができません
マニフェスト.json:
{
"name": "SEO Analytic",
"description": "Adds a print button to the browser.",
"version": "1.2",
"manifest_version": 2,
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
],
"permissions": ["tabs", "http://*/*", "https://*/*"],
"browser_action": {
"default_title": "SEO Analytic",
"default_popup": "popup.html"
}
}
popup.js:
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {method: "getText"}, function(response) {
if (response.method == "getText") {
alltext = response.data;
alert(alltext);
}
});
});
content.js:
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if (request.method == "getText") {
sendResponse({
data: document.body.outerHTML,
method: "getText" // same as innerText
});
}
});