Reputation: 24886
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.)
Upvotes: 7
Views: 2493
Reputation: 646
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:
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
Warnings:
{ 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 via chrome.runtime.sendMessage
or similar chrome.runtime.*
methods.Upvotes: 10