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.)
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.)
Share asked Jul 11, 2020 at 2:34 VolomikeVolomike 24.9k22 gold badges124 silver badges217 bronze badges 2- 1 No. There's no such feature, crbug./1074161 – woxxom Commented Jul 11, 2020 at 4:53
- 1 It would be nice to have API( – Ng Atom Commented Sep 22, 2020 at 16:57
1 Answer
Reset to default 10Here'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:
async function checkIsPinned(){
let userSettings = await chrome.action.getUserSettings();
if(userSettings.isOnToolbar == false){
chrome.tabs.create({ url: 'https://example.'});
}
}
//Check if extension is pinned
checkIsPinned();
This code is adapted from https://github./rustyzone/is-ext-pinned
Warnings:
- It requires Manifest V3.
- It only works when called from pop-up script (e.g. the one that runs when user clicks the extension icon on toolbar) or from service worker.
- It doesn't work from content script. That is, it always returns
{ isOnToolbar: false }
regardless of whether your extension's icon is pinned or not. You need to send a request to your service worker, run the code there, and then send the response back to content script. You can do that viachrome.runtime.sendMessage
or similarchrome.runtime.*
methods. - As of 2023-01-02, it's not supported in Safari (see details).