Giter Site home page Giter Site logo

sinanbekar / browser-extension-react-typescript-starter Goto Github PK

View Code? Open in Web Editor NEW
95.0 5.0 13.0 434 KB

šŸš€ React & TypeScript Starter for developing web extensions with hot reload!

License: MIT License

JavaScript 7.31% TypeScript 87.28% CSS 0.50% HTML 4.92%
chrome-extension react typescript browser-extension vitejs tailwindcss eslint google-chrome jest prettier

browser-extension-react-typescript-starter's Introduction

Sinan Bekar

Full Stack Developer

Ā Ā Linkedin Badge Ā Ā Gmail Badge Ā Ā Medium Badge Ā Ā Twitter Badge

browser-extension-react-typescript-starter's People

Contributors

dependabot[bot] avatar renovate[bot] avatar sinanbekar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

browser-extension-react-typescript-starter's Issues

storage: createJSONStorage(() => localstorage) may lost data

I suggest use this:

// ...
      {
        name: 'preference-storage',
        storage: createJSONStorage(() => getExtensionStorage('preference-storage')),
      },

and

/* eslint-disable security-node/detect-crlf */
import { StateStorage } from 'zustand/middleware';

export const getExtensionStorage = (storageName: string): StateStorage => ({
  getItem: async (key: string): Promise<string | null> => {
    console.log(key, `has been retrieved in ${storageName}`);
    const result = await chrome.storage.sync.get(`${storageName}-${key}`);
    return result[`${storageName}-${key}`] as string | null;
  },
  setItem: async (key: string, value: string): Promise<void> => {
    console.log(key, 'with value', value, `has been saved in ${storageName}`);
    await chrome.storage.sync.set({ [`${storageName}-${key}`]: value });
  },
  removeItem: async (key: string): Promise<void> => {
    console.log(key, `has been deleted from ${storageName}`);
    await chrome.storage.sync.remove(`${storageName}-${key}`);
  },
});

Otherwise I found settings disappear after a while.

How can I add script.js?

Usually in vanilla js I use content_script.js that will inject script.js to the page but I can't find any example related to that?

const container = document.head || document.documentElement
const scriptTag = document.createElement('script')
scriptTag.setAttribute('async', 'false')
scriptTag.src = chrome.runtime.getURL('script.js')
container.insertBefore(scriptTag, container.children[0])
container.removeChild(scriptTag)

Second question is where to place that script.ts to trigger script.js build and include it in HMR?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update dependency @testing-library/react to v15
  • chore(deps): update dependency eslint to v9
  • fix(deps): update dependency @reduxjs/toolkit to v2
  • fix(deps): update dependency react-redux to v9
  • šŸ” Create all rate-limited PRs at once šŸ”

Pending Status Checks

These updates await pending status checks. To force their creation now, click the checkbox below.

  • chore(deps): update dependency @testing-library/jest-dom to v6
  • chore(deps): update dependency eslint-config-prettier to v9
  • chore(deps): update dependency eslint-plugin-prettier to v5
  • chore(deps): update dependency prettier to v3
  • chore(deps): update dependency rimraf to v5
  • chore(deps): update dependency typescript to v5
  • chore(deps): update typescript-eslint monorepo to v7 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/checkout v3
  • actions/setup-node v3
  • actions/checkout v3
  • actions/setup-node v3
npm
package.json
  • @eduardoac-skimlinks/webext-redux 3.0.1-release-candidate
  • @reduxjs/toolkit ^1.9.5
  • @twind/core ^1.1.3
  • @twind/preset-autoprefix ^1.0.7
  • @twind/preset-tailwind ^1.1.4
  • lodash-es ^4.17.21
  • react 18.2.0
  • react-dom 18.2.0
  • react-redux ^8.1.0
  • redux-persist-webextension-storage ^1.0.2
  • reduxjs-toolkit-persist ^7.2.1
  • webextension-polyfill ^0.10.0
  • @crxjs/vite-plugin ^2.0.0-beta.17
  • @testing-library/jest-dom ^5.16.5
  • @testing-library/react ^14.0.0
  • @testing-library/user-event ^14.4.3
  • @types/fs-extra ^11.0.1
  • @types/jest ^29.5.2
  • @types/lodash-es ^4.17.7
  • @types/react ^18.2.12
  • @types/react-dom ^18.2.5
  • @types/redux-persist-webextension-storage ^1.0.0
  • @types/webextension-polyfill ^0.10.0
  • @typescript-eslint/eslint-plugin ^5.59.11
  • @typescript-eslint/parser ^5.59.11
  • @vitejs/plugin-react ^4.0.0
  • autoprefixer ^10.4.8
  • construct-style-sheets-polyfill ^3.1.0
  • eslint ^8.42.0
  • eslint-config-prettier ^8.8.0
  • eslint-plugin-prettier ^4.2.1
  • eslint-plugin-react ^7.32.2
  • eslint-plugin-react-hooks ^4.6.0
  • fs-extra ^11.1.1
  • identity-obj-proxy ^3.0.0
  • jest ^29.5.0
  • jest-chrome ^0.8.0
  • jest-environment-jsdom ^29.5.0
  • nano-staged ^0.8.0
  • npm-run-all2 ^6.0.5
  • postcss ^8.4.24
  • prettier ^2.7.1
  • rimraf ^3.0.2
  • simple-git-hooks ^2.8.0
  • tailwindcss ^3.3.2
  • ts-jest ^29.1.0
  • typescript 4.9.5
  • vite ^4.3.9

  • Check this box to trigger a request for Renovate to run again on this repository

CSP Issue when running HMR-enabled dev build on Firefox 117.0

Error messages:

Content-Security-Policy: The pageā€™s settings blocked the loading of a resource at http://localhost:5173/@vite/env (ā€œscript-srcā€).
Content-Security-Policy: The pageā€™s settings blocked the loading of a resource at http://localhost:5173/@crx/client-worker (ā€œscript-srcā€).
Content-Security-Policy: The pageā€™s settings blocked the loading of a resource at http://localhost:5173/background/index.ts (ā€œscript-srcā€).

Popup:
image

Steps to reproduce:

  1. npm run dev to build dist and start vite
  2. npm run firefox-mv2-build to build dist-firefox-v2 from HMR-enabled chrome dist
  3. Load unpacked extension at $PROJECT_DIR/dist-firefox-v2/manifest.json via about:debugging#/runtime/this-firefox > Load Temporary Add-on...
  4. Inspect logs via about:debugging#/runtime/this-firefox > [Dev] Browser Extension TypeScript & React Starter > Inspect

CSS Modules not reloading

I might be missing something, but I was running with yarn dev and everything works with hot reloading except the CSS modules in the content folder. When I change the CSS nothing changes, even when I hard reload the page and extension. Any ideas on this?

Also is it possible to use Tailwind when injecting content into the page?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.