Trigger a function when opening the Popup?

I know you can create a popup.tsx file, to show JSX when clicking on the extension icon. Is it possible to trigger a function instead of render content, when clicking on the extension icon? For example, when user clicks on the extension icon, instead of showing content in the popup window - trigger a function to change storage state? Thanks in advance
7 Replies
lab
lab16mo ago
Yeah, you can do this in background.ts:
chrome.action.onClicked.addListener((tab) => {
});
chrome.action.onClicked.addListener((tab) => {
});
Make sure to remove popup.tsx
sirhaveri
sirhaveriOP16mo ago
Thanks a lot
pikaq_93257
pikaq_9325715mo ago
Hello!
chrome.action.onClicked is a chrome API and not working with firefox. Is there a plasmo abstraction of browser action that works on both chrome and firefox? 🙏
JustineM
JustineM14mo ago
Hey, I am working with Pikaq, does someone have an answer here? Thanks!
YAGPDB.xyz
YAGPDB.xyz14mo ago
Gave +1 Rep to @Pikaq
lab
lab14mo ago
You can try with firefox-mv3 build or use: https://github.com/mozilla/webextension-polyfill
GitHub
GitHub - mozilla/webextension-polyfill: A lightweight polyfill libr...
A lightweight polyfill library for Promise-based WebExtension APIs in Chrome - GitHub - mozilla/webextension-polyfill: A lightweight polyfill library for Promise-based WebExtension APIs in Chrome
Avi
Avi13mo ago
const action = chrome.action || chrome.browserAction;
action.addListener(() => {...});
const action = chrome.action || chrome.browserAction;
action.addListener(() => {...});
Want results from more Discord servers?
Add your server