Detect Chrome Extension Pinned in Javascript - Stack Overflow

The latest Chrome browser now shows a puzzle icon and doesn't automatically pin your Chrome Extens

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742264014a4411439.html

相关推荐

  • Detect Chrome Extension Pinned in Javascript - Stack Overflow

    The latest Chrome browser now shows a puzzle icon and doesn't automatically pin your Chrome Extens

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信