我正在嘗試編寫一個名爲'btn3'的按鈕的Chrome擴展。當我點擊Chrome擴展程序中的那個按鈕(popup.html)時,它會點擊網頁上的一個按鈕。網頁上的按鈕有以下標識:「常規輔助鍵發送消息」Chrome.tabs.executeScript - 製表符未定義
2個問題:
- 我得到的「標籤沒有定義」的錯誤chrome.tabs.executeScript在下面的代碼中。我該如何解決這個問題?
- 我在content_scripts.js中寫錯了嗎?
謝謝!
腳本在鉻擴展窗口的按鈕的
document.addEventListener('DOMContentLoaded', function(){
document.getElementById('btn3').addEventListener('click', sendInMail)
});
sendInMail = function(){
chrome.tabs.executeScript(tabs[0], {file: "content_script.js"});
}
content_scripts.js
alert("content_script is working!");
function clickSendInMailButton() {
var SendInMailButton = document.getElementsByClassName("regular-secondary-button send-message"),
SendInMailButton.click();
}
clickSendInMailButton();
的manifest.json
{
"manifest_version": 2,
"name": "LinkedIn Assistant",
"description": "This extension makes a LSS AE successful.",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["content_script.js"]
}
],
"chrome_url_overrides" : {
"newtab": "newtab.html"
},
"background": {
"scripts": ["bg.js"]
},
"permissions": [
"tabs", "<all_urls>"
]
}
除了在清單中添加選項卡權限之外,還請確保按照本SO帖子中的建議重新加載擴展程序的權限 - [chrome.tabs.executeScript not working](http://stackoverflow.com/questions/4996194 /鉻標籤 - executescript - 不工作)。 – Teyam