{"id":19230289,"url":"https://github.com/mrloop/web-ext-react","last_synced_at":"2025-04-21T03:30:44.322Z","repository":{"id":45109365,"uuid":"289031831","full_name":"mrloop/web-ext-react","owner":"mrloop","description":"Command line tool to help build, run and test ReactJS based WebExtensions","archived":false,"fork":false,"pushed_at":"2022-01-07T21:20:24.000Z","size":430,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-19T11:53:18.941Z","etag":null,"topics":["react","web-ext","webextensions"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrloop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-20T14:45:11.000Z","updated_at":"2024-06-25T09:37:57.000Z","dependencies_parsed_at":"2022-09-12T18:03:43.810Z","dependency_job_id":null,"html_url":"https://github.com/mrloop/web-ext-react","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrloop%2Fweb-ext-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrloop%2Fweb-ext-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrloop%2Fweb-ext-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrloop%2Fweb-ext-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrloop","download_url":"https://codeload.github.com/mrloop/web-ext-react/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249990866,"owners_count":21357161,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react","web-ext","webextensions"],"created_at":"2024-11-09T15:37:37.904Z","updated_at":"2025-04-21T03:30:44.019Z","avatar_url":"https://github.com/mrloop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Node.js CI](https://github.com/mrloop/web-ext-react/workflows/Node.js%20CI/badge.svg)\n\n# web-ext-react\n\nA CLI tool to help build and run [ReactJS](https://reactjs.org/) based [WebExtensions](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions), integrating [web-ext](https://github.com/mozilla/web-ext) with [create-react-app](https://github.com/facebook/create-react-app)\n\n## Highlights\n\nCreate ReactJS Web Extensions with no build configuration.\n\n- No forked dependencies, uses [create-react-app](https://github.com/facebook/create-react-app) and [web-ext](https://github.com/mozilla/web-ext) as is, enabling you to easily keep up to date.\n- Live reload of JavaScript and CSS as you work on your extension.\n\n## Limitations\n\n**This is a work in progress** extracted from [race-ext-react](https://github.com/mrloop/race-ext-react). Ideally `web-ext-react` would wrap `web-ext` and work as a drop in replacement for better ergonomics, while adding the additional React functionality.\n\n## Documentation\n\n`web-ext-react` should be used with a project created with [`create-react-app`](https://github.com/facebook/create-react-app#creating-an-app). After creating a new react app with `create-react-app my-app` install `web-ext-react` and `web-ext`.\n\n### npm\n\n```sh\nnpm install --save-dev web-ext web-ext-react\n```\n\n### yarn\n\n```sh\nyarn add -D web-ext web-ext-react\n```\n\nNext you can add scripts to `package.json`\n\n```json\n\"scripts\": {\n  \"start:firefox\": \"web-ext-react run | xargs -L1 web-ext run -u http://www.example.org/ -s\",\n  \"build\": \"web-ext-react build | xargs -L1 web-ext build -o -s\"\n}\n```\n\n### index.js\n\n`create-react-app` creates a single app that can be used for all different aspects of a web extensions, content scripts, background script, popups, sidebar and options ui by adding conditional logic to the `src/index.js` auto generated by `create-react-app`, for example.\n\n```js\nif (document.isBackground) {\n  // some background script\n} else if (document.isSidebarAction) {\n  ReactDOM.render(\n    \u003cReact.StrictMode\u003e\n      \u003cSidebar /\u003e\n    \u003c/React.StrictMode\u003e,\n    document.getElementById(\"root\")\n  );\n} else if (document.isBrowserAction) {\n  ReactDOM.render(\n    \u003cReact.StrictMode\u003e\n      \u003cPopup /\u003e\n    \u003c/React.StrictMode\u003e,\n    document.getElementById(\"root\")\n  );\n} else if (document.isOptionsUi) {\n  ReactDOM.render(\n    \u003cReact.StrictMode\u003e\n      \u003cOptions /\u003e\n    \u003c/React.StrictMode\u003e,\n    document.getElementById(\"root\")\n  );\n} else if (document.isContentScripts) {\n  // content script\n  ReactDOM.render(\n    \u003cReact.StrictMode\u003e\n      \u003cApp /\u003e\n    \u003c/React.StrictMode\u003e,\n    document.getElementById(\"root\")\n  );\n}\n```\n\n### extension/manifest.json\n\nYou must create an `extension/manifest.json`\n\n```json\n{\n  \"manifest_version\": 2,\n  \"name\": \"web-ext-react dummy app\",\n  \"version\": \"0.1\",\n\n  \"description\": \"dummy app to test web-ext-react\",\n  \"homepage_url\": \"https://github.com/mrloop/web-ext-react\",\n  \"icons\": {\n    \"48\": \"icon.svg\",\n    \"96\": \"icon.svg\"\n  },\n  \"content_scripts\": [\n    {\n      \"matches\": [\"\u003call_urls\u003e\"],\n      \"js\": [],\n      \"css\": []\n    }\n  ],\n  \"background\": {\n    \"page\": \"background-page.html\"\n  }\n}\n```\n\nNote the \"content_scripts\" JS and CSS arrays are empty and will be populated at build time. We specify that the web extension will also run a background script, also note \"background-page.html\" is auto generated by `web-ext-react`. You don't need to add this yourself, the important part is the conditional invocation of different react components from `index.js`. For this `manifest.json` the `src/index.js` would contain code to run in the background and a content script conditional run depending on context run from.\n\n```js\nif (document.isBackground) {\n  // some background script\n} else if (document.isContentScripts) {\n  // content script\n  ReactDOM.render(\n    \u003cReact.StrictMode\u003e\n      \u003cApp /\u003e\n    \u003c/React.StrictMode\u003e,\n    document.getElementById(\"root\")\n  );\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrloop%2Fweb-ext-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrloop%2Fweb-ext-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrloop%2Fweb-ext-react/lists"}