2012-06-07 33 views
0

有麻煩,wasnt發現任何東西在這裏回答我有什麼:/內容腳本通知

清單:

{ 
    "name": "Item Sniper", 
    "version": "1.0", 
    "description": "Sniper", 
    "browser_action": { 
    "default_icon": "face.png", 
    "default_title": "Sniper" 
    }, 
    "background": { 
    "scripts": ["background.js"] 
    }, 
    "permissions": [ 
    "tabs", 
    "notifications", 
    "http://*/*" 
    ] 
} 

Background.js:

chrome.browserAction.onClicked.addListener(function(tab) { 
    chrome.tabs.executeScript(null,{file: "buy.js"}); 
    } 
); 
chrome.extension.onRequest.addListener(
    function(request, sender, sendResponse) { 
    var notify = webkitNotifications.createNotification(
     'face.png', // icon url - can be relative 
     'Hello!', // notification title 
     'Oh hellow!' // notification body text 
    ); 
}); 

Buy.js [還有更多,但這是通知部分]:

chrome.extension.sendRequest({msg: "Sup?"}, function(response) { // optional callback -  gets response 
    console.log(response.returnMsg); 
}); 

我基本上想要的內容腳本來創建一個通知,但我不知道它是否同時用JS腳本作爲背景堅持是可能的:/

感謝您的幫助, 亞歷

+3

您是否嘗試過這個? – Oliver

+0

'但我不知道是否有可能,而堅持使用js腳本作爲背景'爲什麼它不工作?你測試過了嗎? –

回答

0

background property只可用於使用version 2的清單。如果你想支持這個,你需要將你的清單更新爲以下內容;針對這個版本的Chrome或更新的時

{ 
    "name": "Item Sniper", 
    "version": "1.0", 
    "description": "Sniper", 
    "manifest_version": 2, 
    "minimum_chrome_version": "18", 
    "browser_action": { 
    "default_icon": "face.png", 
    "default_title": "Sniper" 
    }, 
    "background": { 
    "scripts": ["background.js"] 
    }, 
    "permissions": [ 
    "tabs", 
    "notifications", 
    "http://*/*" 
    ] 
} 

注意,我也minimum_chrome_version屬性設置爲18如清單版本2只能被使用。

0

我想你錯過了調用notify.show();在background.js

chrome.extension.onRequest.addListener(
    function(request, sender, sendResponse) { 
    var notify = webkitNotifications.createNotification(
     'face.png', // icon url - can be relative 
     'Hello!', // notification title 
     'Oh hellow!' // notification body text 
    ); 
    notify.show(); 
}); 

http://code.google.com/chrome/extensions/notifications.html#api