Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Chrome Extension Pinned in Javascript

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

like image 841
Volomike Avatar asked Oct 15 '22 02:10

Volomike


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

like image 69
ace973 Avatar answered Nov 15 '22 09:11

ace973