Giter Club home page Giter Club logo

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

View Code? Open in Web Editor NEW
128.0 128.0 20.0 425 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%
browser-extension chrome-extension edge eslint firefox firefox-add-ons google-chrome jest opera-extension prettier react redux redux-persist redux-toolkit tailwindcss typescript vitejs

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

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

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.

  • fix(deps): update dependency webextension-polyfill to ^0.12.0 (webextension-polyfill, @types/webextension-polyfill)
  • fix(deps): update react monorepo to v18.3.1 (react, react-dom)
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency rimraf to v6
  • chore(deps): update testing-library monorepo (major) (@testing-library/jest-dom, @testing-library/react)
  • 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 actions/setup-node action to v4
  • 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 typescript to v5
  • chore(deps): update typescript-eslint monorepo to v8 (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

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?

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.

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?

Invalid Path Characters Error on `yarn dev`

Description

I encountered an error when attempting to start the development server using yarn dev. The error message indicates that there are invalid characters in the file path, which prevents the server from starting.

Steps to Reproduce

  1. Clone the repository.
  2. Run yarn install to install dependencies.
  3. Run yarn dev to start the development server.

Expected Behavior

The development server should start successfully and listen on the specified port.

Actual Behavior

The following error occurs:

yarn dev
yarn run v1.22.22
$ run-s clean && vite
$ run-p clean:*
$ rimraf dist
$ rimraf dist-firefox-v2

VITE v4.3.9 ready in 878 ms

➜ Local: http://localhost:3573/
➜ Network: use --host to expose
➜ press h to show help
E:\Cex\browser-extension-react-typescript-starter\node_modules@crxjs\vite-plugin\node_modules\fs-extra\lib\mkdirs\utils.js:16
const error = new Error(Path contains invalid characters: ${pth})
^

Error: Path contains invalid characters: E:/Cex/browser-extension-react-typescript-starter/src/E:\Cex\browser-extension-react-typescript-starter\dist/content
at checkPath (E:\Cex\browser-extension-react-typescript-starter\node_modules@crxjs\vite-plugin\node_modules\fs-extra\lib\mkdirs\utils.js:16:21)
at module.exports.makeDir (E:\Cex\browser-extension-react-typescript-starter\node_modules@crxjs\vite-plugin\node_modules\fs-extra\lib\mkdirs\make-dir.js:12:3)
at Object. (E:\Cex\browser-extension-react-typescript-starter\node_modules\universalify\index.js:22:13)
at E:\Cex\browser-extension-react-typescript-starter\node_modules@crxjs\vite-plugin\node_modules\fs-extra\lib\output-file\index.js:20:11
at E:\Cex\browser-extension-react-typescript-starter\node_modules\universalify\index.js:22:54 {
code: 'EINVAL'
}

Node.js v20.6.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Environment Information

  • Operating System: Windows 10
  • Node.js Version: v20.6.1
  • Yarn Version: 1.22.22
  • Vite Version: 4.3.9

Additional Information

I have tried running the command prompt with administrator privileges, but the issue persists. It seems that there is a mix of forward slashes (/) and backslashes (\) in the file path, which might be causing the issue.

Any guidance or solutions would be greatly appreciated.

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.