Detect Chrome Extension Pinned in Javascript

Viewed 1083

The latest Chrome browser now shows a puzzle icon and doesn't automatically pin your Chrome Extension. Is there an API to detect if a Chrome Extension has been pinned? Can we detect from Javascript from a web page, or do we have to do the API through the extension itself? (I'm already assuming the extension itself.)

1 Answers

Here's some code you can use to check if your extension is pinned, and if not, send the user to a particular url.

You can put this in your Background.js and it works in Manifest V3.

async function checkIsPinned(){
  let userSettings = await chrome.action.getUserSettings();
  if(userSettings.isOnToolbar == false){
    chrome.tabs.create({ url: 'https://example.com'});
  }
}
//Check if extension is pinned 
checkIsPinned();

This code is adapted from https://github.com/rustyzone/is-ext-pinned

Related