react-typescript-web-extension-starter

repository·main·Indexed 21 days ago

https://github.com/aeksco/react-typescript-web-extension-starter

A professional-grade starter kit for building web extensions compatible with Chrome, Firefox, Brave, and Edge. Built with React, TypeScript, Tailwind CSS, EsLint, Prettier, and Webpack, it includes Storybook for UI development and Jest for testing. The kit provides a complete development environment and includes mocks for webextension-polyfill-ts to allow component testing in isolation.

Tokens
1.1K
Snippets
6
Records
10
Agent score
76%

What's inside react-typescript-web-extension-starter

  1. Available development scripts

    main

    Use the following yarn commands to manage your development workflow:

    • yarn dev: Runs webpack in watch mode for real-time development.
    • yarn storybook: Starts the Storybook server for component isolation.
    • yarn build: Generates a production-ready unpacked extension in the dist directory.
    • yarn test -u: Runs Jest tests and updates snapshots.
    • yarn lint: Runs ESLint to check for code quality issues.
    • yarn prettify: Runs Prettier to format your code.
    yarn dev
    yarn storybook
    yarn build
    yarn test -u
    yarn lint
    yarn prettify
  2. Initialize the Popup component

    main

    The popup entrypoint initializes the React application by rendering the Popup component into the DOM element with the ID popup. It uses webextension-polyfill to query the active tab in the current window before mounting, ensuring the extension context is ready.

    // The entrypoint renders the Popup component into the 'popup' element
    ReactDOM.render(<Popup />, document.getElementById("popup"));
  3. Use the Scroller component

    main

    The Scroller component renders a UI containing two buttons: one for scrolling to the top of the page and one for scrolling to the bottom. It requires two callback functions via props to handle the scroll logic, as the component does not manage the scroll state itself.

    import { Scroller } from './components/scroller/component';
    
    function MyComponent() {
      const handleScrollTop = () => {
        window.scrollTo({ top: 0, behavior: 'smooth' });
      };
    
      const handleScrollBottom = () => {
        window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
      };
    
      return (
        <Scroller 
          onClickScrollTop={handleScrollTop} 
          onClickScrollBottom={handleScrollBottom} 
        />
      );
    }