sinanbekar / browser-extension-react-typescript-starter Goto Github PK
View Code? Open in Web Editor NEW🚀 React & TypeScript Starter for developing web extensions with hot reload!
License: MIT License
🚀 React & TypeScript Starter for developing web extensions with hot reload!
License: MIT License
The dist
is a folder, do I need to add extra steps to bundle it as a file (then upload to github release)?
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”).
npm run dev
to build dist
and start vite
npm run firefox-mv2-build
to build dist-firefox-v2
from HMR-enabled chrome dist
$PROJECT_DIR/dist-firefox-v2/manifest.json
via about:debugging#/runtime/this-firefox
> Load Temporary Add-on...
about:debugging#/runtime/this-firefox
> [Dev] Browser Extension TypeScript & React Starter
> Inspect
https://extensionworkshop.com/documentation/develop/manifest-v3-migration-guide/
Seems FireFox is also recommending V3. But I found it is impossible to pick dist folder from about:addons of Firefox, why? (After running pnpm dev
)
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
webextension-polyfill
, @types/webextension-polyfill
)react
, react-dom
)@testing-library/jest-dom
, @testing-library/react
)These updates await pending status checks. To force their creation now, click the checkbox below.
@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
)These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.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
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
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
?
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.
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?
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.
yarn install
to install dependencies.yarn dev
to start the development server.The development server should start successfully and listen on the specified port.
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.