This time, the button will not appear and the console log will read “No extension”.
The extension is currently installed and enabled so the “Get the screen” button will appear the current extension version will be logged in the console.ĭisable the extension from the Chrome extensions settings (chrome://extensions) and reload the page. Test this out by serving chrome/index.html over localhost (I use serve for this) and opening the page in Chrome.
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.Īdd the following code to the top of extension.js In order to detect the extension we need to be able to send back a simpler message. 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. You’ll need these lines in your manifest.json and a background script that listens for incoming messages using the ( function, like the example project’s extension.js. Note: If you are working with an extension that does not use a background page then you will need to add one. Our app can test for that null value and decide whether to continue with the rest of the screen capture flow or not. 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. This response parameter is what we will use to detect whether the extension is present. 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.