0

問題があり、私が持っているものに答える何かをここで見つけることができませんでした:/

マニフェスト:

{
   "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スクリプトを使用しているときにそれが可能かどうかわかりませんでした:/

助けてくれてありがとう、アレックス

4

2 に答える 2

0

background プロパティは、バージョン 2を使用するマニフェストでのみ使用できます。これをサポートしたい場合は、マニフェストを次のように更新する必要があります。

{
   "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マニフェスト バージョン 2 は、このバージョンの Chrome 以降を対象とする場合にのみ使用できるため、プロパティも 18 に設定していることに注意してください。

于 2012-06-07T07:39:11.040 に答える
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

于 2012-06-07T11:33:07.880 に答える