最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Detect Chrome Extension Pinned in Javascript - Stack Overflow

programmeradmin7浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 10

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.'});
  }
}
//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 via chrome.runtime.sendMessage or similar chrome.runtime.* methods.
  • As of 2023-01-02, it's not supported in Safari (see details).
发布评论

评论列表(0)

  1. 暂无评论