MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / clickMenuCallback

Function clickMenuCallback

chrome-extension/src/service_worker.js:32–46  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

30 * sent back here. After that, imageClassifier's analyzeImage method.
31 */
32function 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.

Callers

nothing calls this directly

Calls 1

analyzeImageMethod · 0.80

Tested by

no test coverage detected