diff --git a/docs/METRICS.md b/docs/METRICS.md index e4fd362531..b5d7caaa22 100644 --- a/docs/METRICS.md +++ b/docs/METRICS.md @@ -114,7 +114,7 @@ The primary change was in `server/src/pages/shot/share-buttons.js` 2. ~~Daily ping (attempt roughly every 24 hours) `addon/daily-ping`~~ (removed for launch) 1. [x] Click shot button `addon/start-shot/toolbar-pageshot-button` 2. [ ] Use keyboard shortcut to start shot `addon/start-shot/keyboard-shortcut` (accel-alt-control-c) (FIXME: not yet implemented) -3. [ ] Use the right-click context menu to start a shot `addon/start-shot/context-menu` (FIXME: not yet implemented) +3. [x] Use the right-click context menu to start a shot `addon/start-shot/context-menu` 2. [x] Make a selection `addon/make-selection/selection-drag` with `cd2: {px width}, cd1: {px height}` 3. [x] Make a selection by clicking on an element `addon/make-selection/selection-click` with `cd2: {px width}, cd1: {px height}` 4. [x] Click but fail to find an element that can be selected `addon/no-selection/no-element-found` (error case, not sure when it happens) diff --git a/webextension/background/main.js b/webextension/background/main.js index cafac4bcb6..4e75b0df8e 100644 --- a/webextension/background/main.js +++ b/webextension/background/main.js @@ -29,11 +29,29 @@ window.main = (function () { chrome.browserAction.onClicked.addListener(function(tab) { sendEvent("start-shot", "toolbar-pageshot-button"); - loadSelector().catch((e) => { - console.error("Error loading scripts:", e); - }); + catcher.watchPromise(loadSelector()); }); + chrome.contextMenus.create({ + id: "create-pageshot", + title: "Create Page Shot", + contexts: ["page"] + }, () => { + if (chrome.runtime.lastError) { + catcher.unhandled(new Error(chrome.runtime.lastError.message)); + } + }); + + chrome.contextMenus.onClicked.addListener(catcher.watchFunction((info, tab) => { + if (! tab) { + // Not in a page/tab context, ignore + return; + } + sendEvent("start-shot", "context-menu"); + catcher.watchPromise(loadSelector()); + })); + + communication.register("sendEvent", (...args) => { catcher.watchPromise(sendEvent(...args)); // We don't wait for it to complete: diff --git a/webextension/manifest.json.template b/webextension/manifest.json.template index 2886643d4d..e16921191b 100644 --- a/webextension/manifest.json.template +++ b/webextension/manifest.json.template @@ -60,6 +60,7 @@ "storage", "notifications", "clipboardWrite", + "contextMenus", "", "http://localhost:10080/" ]