2017-10-05 74 views
-1

我遇到了onclick瀏覽器操作問題。 它所有的時間顯示TypeError:瀏覽器沒有定義,如果我確實放在嘗試捕獲 嘗試手動inseritng到Firefox的控制檯,沒有成功仍然沒有定義。 使用firefox 55. 如何解決這個問題?如何修復TypeError:瀏覽器沒有定義?

console.log("Start 1") 
 
function run(){console.log(1)} 
 
browser.browserAction.onClicked.addListener(run); 
 

 
var interval1Id = setInterval(function(){ 
 

 
\t var id = document.querySelector(".myclass").id 
 

 
\t document.getElementById('m1).contentWindow.document.getElementById(id).click(); 
 
\t var newDate = new Date(); 
 
    \t console.log("Function executes at : " +newDate) 
 
},10000); \t

清單

{ 
"applications": { 
    "gecko": { 
    "id": "[email protected]", 
    "strict_min_version": "52.0" 
    } 
}, 
"browser_action": { 
    "default_icon": { 
     "18": "icons/btn18.png", 
     "38": "icons/btn18.png" 
    }, 
    "default_title": "Whereami1?" 
    }, 
    "manifest_version": 2, 
    "name": "FF 1a", 
    "version": "1a", 
    "description": "Refresh", 
    "background": { 
    "scripts": ["b.js"] 
    }, 
    "content_scripts": [ 
    { 
    "matches" : ["https://*/*"], 
    "js": ["scr.js"] 
    } 
    ], 
    "permissions": ["webNavigation","tabs","notifications","activeTab"], 
    "web_accessible_resources": ["icons/btn18.png"] 

} 
+0

你到底想達到什麼目的?沒有名爲瀏覽器的全局變量。 – Daniel

+0

'瀏覽器'對象很可能不適用於內容腳本,並且只能在後臺腳本中使用 –

+0

如果您要檢查Firefox web ext開發人員指南,則在他們的示例中他們使用此變量。 喜歡這裏:https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Your_second_WebExtension 我想通過點擊FF工具欄中我的Web擴展的圖標來運行函數 –

回答

0

Output of background script goes to specific Debug page, not to output of firefox console . Extensions-> Debug Extension -> Allow debugging-> Debug on extensions. New console outputs, where everything comes to display Browser variable only supported in Debug console, not in developer tools console

+0

雖然這是中等準確的,但如果是引用,則需要聲明源。此外,無法根據您的問題確定這是實際的答案。事實上,根據你的問題,它*不能是唯一需要的或你的問題。它確實涵蓋了你的問題隱含的部分內容。它通常只涵蓋你想要訪問擴展的上下文中的控制檯的問題,而不是頁面上下文。 – Makyen

相關問題