2016-04-19 14 views
1

クロムの内線を右クリックすると、拡張機能のコンテキストメニューにカスタムオプションを追加する方法はありますか?どんな入力も感謝します。私はcontextMenusを確認してくださいクロムエクステンションのコンテキストメニューのカスタムオプションを追加する

Manifest.json 
    { 
     "name": "Sample", 
     "version": "0.1", 
     "manifest_version": 2, 
     "background": { 
     "scripts": ["background.js"] 
     }, 
     "page_action": { 
     "default_title": "Sample" 
     }, 
     "permissions": [ 
     "contextMenus" 
     ] 
    } 

Background.js

chrome.contextMenus.create({ 
    title: "Option22", 
    contexts: ["page_action"], 
    onclick: function() { 
     console.log("click"); 
    } 
}); 

chrome.runtime.onInstalled.addListener(function() { 
    // Replace all rules ... 
    chrome.declarativeContent.onPageChanged.removeRules(undefined, function() { 
    // With a new rule ... 
    chrome.declarativeContent.onPageChanged.addRules([ 
     { 
     // That fires when a page's URL contains a 'g' ... 
     conditions: [ 
      new chrome.declarativeContent.PageStateMatcher({ 
      pageUrl: { urlContains: 'g' }, 
      }) 
     ], 
     // And shows the extension's page action. 
     actions: [ new chrome.declarativeContent.ShowPageAction() ] 
     } 
    ]); 
    }); 
}); 
+0

@Haibara愛:私は[この](http://stackoverflow.com/questions/13783500/context-menus-in-chrome-extensions)質問はおよそであると信じてブラウザのコンテキストメニュー。私の質問は、拡張機能のコンテキストメニューです。 –

+0

ご迷惑をおかけして申し訳ありませんが、私は "ブラウザアクション"の回答を掲載しました。 –

答えて

3

を試してみました enter image description here

更新 サンプルページアクション拡張機能は、コンテキスト"browser_action"

を設定することで、拡張コンテキストメニューを作成することができますマニフェスト.json

{ 
    "name": "36715370", 
    "version": "0.1", 
    "manifest_version": 2, 
    "background": { 
     "scripts": ["background.js"] 
    }, 
    "browser_action": { 
     "default_title": "Your browser action title" 
    }, 
    "permissions": [ 
     "contextMenus" 
    ] 
} 

background.js

chrome.contextMenus.create({ 
    title: "Your title here", 
    contexts: ["browser_action"], 
    onclick: function() { 
     console.log("click"); 
    } 
}); 
+1

私はブラウザのコンテキストメニューについてこれを信じています。私の質問は、拡張機能のコンテキストメニューです(拡張機能アイコンを右クリックしてください)。 –

+0

@SarathChand、この回答は「拡張機能アイコンを右クリックする」ためのものです。試してみることもできます。 –

+0

はい、うまくいきました。 –

関連する問題