这是新手,谢谢您的帮助。
当由popup.html-> popup.js调用时,此方法效果很好。但是,当我将manifest.json设置为通过content_scripts执行时,返回错误无法读取属性'executeScript'
manifest.json:
...
"content_scripts": [{
"matches": ["https://www.google.com/*"],
"js": ["jQuery Core 3.4.1.js", "content.js"],
"run_at": "document_end"
}],
"permissions": [
"activeTab"
]
...
content.js:
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse)
{
if (request.action === "getSource")
{
message.innerText = request.source;
}
});
function onWindowLoad() {
var message = document.querySelector('#message');
chrome.tabs.executeScript(null, {
file: "getPagesSource.js"
},
function ()
{
if (chrome.runtime.lastError) {
message.innerText = "There was an error injecting script : \n" + chrome.runtime.lastError.message;
}
});
}
window.onload = onWindowLoad;