Help with showing script ui. (content.tsx) when clicking on chrome extension
Hi! I'm trying to show the script ui (modal content using a content script ui) when clicking on the chrome extension icon instead of showing a popup.
I have this in content.tsx:
my background.ts:
What I'm confused on:
- do we still have to compile the tsx/ts files to js using tsc? if so, would those compiled files be in the .plasmo or build directory?
- do we need to make any changes in package.json or tsconfig.json as well?
thanks ahead!
2 Replies
@AP Did you figure this out ? Currently also struggling to make this work :/
@AP Figured it out you need to use the Storage hook:
In background.ts
import { Storage } from "@plasmohq/storage"
chrome.action.onClicked.addListener(async (tab) => {
console.log(" I waass clicked")
await storage.set("isOpen", true)
}) const storage = new Storage()storage.watch({
"isOpen": (c) => {
console.log(c.newValue)
},
})
In Content.tsx
const [isOpenStorage, setIsOpenStorage] = useStorage("isOpen", false)
And render conditionally on the isOpenStorageyep did something similar