* What action to take when someone clicks the right-click menu option. * Here it takes the url of the right-clicked image and the current tabId, and * send them to the content script where the ImageData will be retrieved and * sent back here. After that, imageClassifier's analyzeImage method.
(info, tab)
| 30 | * sent back here. After that, imageClassifier's analyzeImage method. |
| 31 | */ |
| 32 | function clickMenuCallback(info, tab) { |
| 33 | const message = { action: 'IMAGE_CLICKED', url: info.srcUrl }; |
| 34 | chrome.tabs.sendMessage(tab.id, message, (resp) => { |
| 35 | if (!resp.rawImageData) { |
| 36 | console.error( |
| 37 | 'Failed to get image data. ' + |
| 38 | 'The image might be too small or failed to load. ' + |
| 39 | 'See console logs for errors.'); |
| 40 | return; |
| 41 | } |
| 42 | const imageData = new ImageData( |
| 43 | Uint8ClampedArray.from(resp.rawImageData), resp.width, resp.height); |
| 44 | imageClassifier.analyzeImage(imageData, info.srcUrl, tab.id); |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Adds a right-click menu option to trigger classifying the image. |
nothing calls this directly
no test coverage detected