This is a boilerplate and starter for Chrome browser extension, built with Wxt、 React、 Tailwind css 、Shadcn ui and Typescript. Support dark mode and localization
Before you get started, please make sure you have the following installed:
Open your editor
Open the Terminal
Ctrl + ~
for Windows or Control + ~
for Mac in VS Code).Clone the Repository and Navigate into the Directory
Once your terminal is open, you can clone the repository and move into the directory by running the commands below.
For Mac/Linux users :apple: :penguin:
git clone [email protected]:imtiger/wxt-react-shadcn-tailwindcss-chrome-extension.git
cd wxt-react-shadcn-tailwindcss-chrome-extension
npm install
npm run dev
For Windows users :windows:
git clone [email protected]:imtiger/wxt-react-shadcn-tailwindcss-chrome-extension.git
cd wxt-react-shadcn-tailwindcss-chrome-extension
npm install
npm run dev
The browser will be auto opened
The locales file in the locales folder ,and you can edit it.
initTranslations(i18nConfig.defaultLocale, ["common", "content"])
Because Tailwind CSS uses rem by default, and rem is computed based on the font-size of the html element on the page, even if a content-script uses shadow dom, the internal elements' rem are also calculated based on the root html element's font-size of the host page. Therefore, to prevent style differences in the plugin due to varying font-sizes set by different websites, we can modify the default configuration of Tailwind CSS, allowing it to calculate directly in pixels.
npm install @thedutchcoder/postcss-rem-to-px
//postcss.config.js
export default {
plugins: {
tailwindcss: {},
'@thedutchcoder/postcss-rem-to-px': {}, // you can add option like the base font size
autoprefixer: {},
},
};
Add new component
npx shadcn-ui@latest add
Not trigger the click event listener.
When a popup or side panel is defined, and set
browser.sidePanel.setPanelBehavior({openPanelOnActionClick: true}).catch((error: any) => console.error(error));
clicking on the browser extension icon won't trigger the listening event,and just open the side panel.
//monitor the event from extension icon click
browser.action.onClicked.addListener((tab) => {
// 发送消息给content-script.js
console.log("click icon")
console.log(tab)
browser.tabs.sendMessage(tab.id!, {messageType: MessageType.clickExtIcon});
});
Full-Stack Engineer
Once worked at Tencent and Alibaba
If this project is helpful to you, star the repo and buy be a coffee, thank you guys.