-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcontext-menu.js
More file actions
26 lines (24 loc) · 1.06 KB
/
context-menu.js
File metadata and controls
26 lines (24 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// This script creates a context menu item for the extension's toolbar icon.
// Create the context menu item when the extension is installed or updated.
// This listener can coexist with other onInstalled listeners.
chrome.runtime.onInstalled.addListener(() => {
// Remove existing menu items first to prevent duplicate ID errors on reload
chrome.contextMenus.removeAll(() => {
// Use 'chrome.contextMenus.create' to add an item.
chrome.contextMenus.create({
id: "open-welcome",
title: "Open Welcome page",
contexts: ["action"] // Show this item only when right-clicking the extension's toolbar icon.
});
});
});
// Add a listener for when a context menu item is clicked.
chrome.contextMenus.onClicked.addListener((info, tab) => {
// Check if the clicked menu item's ID is the one we created.
if (info.menuItemId === "open-welcome") {
// If it is, create a new tab with the welcome page.
chrome.tabs.create({
url: chrome.runtime.getURL('welcome.html')
});
}
});