2014-09-22 105 views
1

我一直在尋找過去幾天的方法來讓我的擴展自動運行;它在我使用chrome.browserAction.onClicked.addListener時有效,但我希望它可以在無需手動啓用的情況下運行。我想我的manifest.json配置錯誤的這個任務。如果有人能指出我會朝着正確的方向發展,那就太棒了!如何製作自動運行的Chrome擴展程序?

的manifest.json

{ 
    "manifest_version": 2, 

    "name": "Rocket", 
    "version": "1.0", 
    "description": "Feast", 

    "icons": { 
    "128" : "icon.png" 
    }, 

    "browser_action": { 
    "default_icon": "icon8.png" 
    }, 

    "background": { "page": "background.html" }, 
    "permissions": [ "tabs", "http://*/*", "https://*/*" ], 

    "web_accessible_resources": [ "contentscript.js", "jquery-2.1.1.js", "background.js"] 
} 

background.html

<html> 
<head> 
<script src="background.js"></script> 
</head> 
</html> 
+1

不要在啓動時自動運行大多數擴展嗎? – 2014-09-22 21:33:39

+0

@SterlingArcher是的,這就是爲什麼我想爲我正在開發的擴展添加相同的功能。 – xxyyzz 2014-09-22 21:51:03

+2

擴展確實自動啓動。 'background.js'中的任何頂級代碼都會執行。你想用它做什麼? – Xan 2014-09-22 21:51:23

回答

0

如果使用chrome.browserAction.onClicked.addListener到 '開始',你可能想使用的setInterval程序()在而不是你的JavaScript,它會讓你的代碼每X毫秒運行一次。 http://www.w3schools.com/js/js_timing.asp

編輯:我剛剛在Google支持網站上發現了這一點。 「請儘量將[活動頁面]留在持久背景頁面,以便進行新的開發,並開始將現有背景頁面遷移到此新模型。」https://developer.chrome.com/extensions/event_pages#transition