A web page can send a message to a specific extension by calling the sendMessage function providing the extension ID, an object as a request and a callback function which has a response parameter. This response parameter is what we will use to detect whether the extension is present.

We can do this because in Chrome sending a message to an extension that is not there will result in the callback being executed with null as the response parameter.. Our app can test for that null value and decide whether to continue with the rest of the screen capture flow or not.

Note: If you are working with an extension that does not use a background page then you will need to add one. You’ll need these lines in your manifest.json and a background script that listens for incoming messages using the chrome.runtime.onMessageExternal.addListener( function, like the example project’s extension.js .

Responding to messages

The extension is already responding to messages, however it currently only responds to a single type and only with a stream of the user selected screen. In order to detect the extension we need to be able to send back a simpler message. That message could just be a boolean, but to be more useful for the future, we will reach into our extension manifest and return the current version of the extension.