fancy-intern-4869
06/25/2022, 6:54 PMbrowserAction.onClicked
behaviourfancy-intern-4869
06/25/2022, 6:54 PMpopup.tsx
required for plasmo to work?
Here's what I have done:
1. pnpm dlx plasmo
2. Remove popup.tsx
3. create service worker
typescript
// apps/browser/background.ts
chrome.browserAction.onClicked.addListener(async (currentTab) => {
chrome.tabs.sendMessage(currentTab.id, { greeting: "hello" }, (response) =>
console.log(response.farewell)
)
})
export {}
4. Create content script
typescript
import type { PlasmoContentScript } from "plasmo"
export const config: PlasmoContentScript = {
matches: ["https://*/*"]
}
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log(
sender.tab
? "from a content script:" + sender.tab.url
: "from the extension"
)
if (request.greeting === "hello") sendResponse({ farewell: "goodbye" })
})
Here's a video of the basic background/content messaging not working:
https://www.loom.com/share/f771ad21f07c4813843a469edb2d8c08quaint-rainbow-21282
06/25/2022, 7:01 PMlimited-farmer-52140
06/25/2022, 8:06 PMfancy-intern-4869
06/25/2022, 8:30 PMfancy-intern-4869
06/26/2022, 6:24 PMchrome.browserAction
is undefined
. How is that even possible I wonder?fancy-intern-4869
06/26/2022, 6:36 PMfancy-intern-4869
06/26/2022, 6:38 PMfancy-intern-4869
06/26/2022, 6:56 PMbrowserAction
API, instead of the new action
.fancy-intern-4869
06/26/2022, 6:57 PM