Advertisement
elirang

contextMenus

Jul 27th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. manifest.json:
  2. {
  3. "name": "P",
  4. "version": "1.0",
  5. "description": "P",
  6.  
  7. "permissions": [
  8. "contextMenus"
  9. ],
  10. "background": {
  11. "scripts": ["background.js"],
  12. "persistent": false
  13. },
  14. "manifest_version": 2
  15. }
  16.  
  17.  
  18. background.js:
  19. function genericOnClick(info, tab) {
  20. console.log("item " + info.menuItemId + " was clicked");
  21. console.log("info: " + JSON.stringify(info));
  22. console.log("tab: " + JSON.stringify(tab));
  23. }
  24.  
  25. chrome.runtime.onInstalled.addListener(function() {
  26. chrome.contextMenus.create({
  27. "id": "sampleContextMenu",
  28. "title": "Sample Context Menu",
  29. "contexts": ["all"]
  30. });
  31. console.log("created context menu");
  32. chrome.contextMenus.onClicked.addListener(function(info, tab) {
  33. if (info.menuItemId == "sampleContextMenu") {
  34. alert("bla bla bla");
  35. console.log("menu item was clicked");
  36. }
  37. });
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement