Giter VIP home page Giter VIP logo

web-extension-starter's Introduction

🚀 web-extension-starter

Web Extension starter to build "Write Once Run on Any Browser" extension

🙋‍♂️ Made by @abhijithvijayan

Donate: PayPal, Patreon

Buy Me a Coffee


❤️ it? ⭐️ it on GitHub or Tweet about it.

🧙‍♂️ React + TypeScript = This branch

😨 React + JavaScript = Checkout react-javascript branch

👶🏼 HTML + JavaScript = Checkout master branch

Features

  • Cross Browser Support (Web-Extensions API)
  • Browser Tailored Manifest generation
  • Automatic build on code changes
  • Auto packs browser specific build files
  • SASS styling
  • TypeScript by default
  • ES6 modules support
  • React UI Library by default
  • Smart reload

Browser Support

Chrome Firefox Opera Edge Yandex Brave vivaldi
49 & later ✔ 52 & later ✔ 36 & later ✔ 79 & later ✔ Latest ✔ Latest ✔ Latest ✔

Used by extensions in production that has over 100,000+ users.

and many more...

Use this template

Create a new directory and run

curl -fsSL https://github.com/abhijithvijayan/web-extension-starter/archive/react-typescript.tar.gz | tar -xz --strip-components=1

🚀 Quick Start

Ensure you have

Then run the following:

  • npm install to install dependencies.
  • npm run dev:chrome to start the development server for chrome extension
  • npm run dev:firefox to start the development server for firefox addon
  • npm run dev:opera to start the development server for opera extension
  • npm run build:chrome to build chrome extension
  • npm run build:firefox to build firefox addon
  • npm run build:opera to build opera extension
  • npm run build builds and packs extensions all at once to extension/ directory

Development

  • npm install to install dependencies.

  • To watch file changes in development

    • Chrome
      • npm run dev:chrome
    • Firefox
      • npm run dev:firefox
    • Opera
      • npm run dev:opera
  • Load extension in browser

  • Chrome

    • Go to the browser address bar and type chrome://extensions
    • Check the Developer Mode button to enable it.
    • Click on the Load Unpacked Extension… button.
    • Select your browsers folder in extension/.
  • Firefox

    • Load the Add-on via about:debugging as temporary Add-on.
    • Choose the manifest.json file in the extracted directory
  • Opera

    • Load the extension via opera:extensions
    • Check the Developer Mode and load as unpacked from extension’s extracted directory.

Production

  • npm run build builds the extension for all the browsers to extension/BROWSER directory respectively.

Note: By default the manifest.json is set with version 0.0.0. The webpack loader will update the version in the build with that of the package.json version. In order to release a new version, update version in package.json and run script.

If you don't want to use package.json version, you can disable the option here.

Generating browser specific manifest.json

Update source/manifest.json file with browser vendor prefixed manifest keys

{
  "__chrome__name": "SuperChrome",
  "__firefox__name": "SuperFox",
  "__edge__name": "SuperEdge",
  "__opera__name": "SuperOpera"
}

if the vendor is chrome this compiles to:

{
  "name": "SuperChrome",
}

Add keys to multiple vendors by separating them with | in the prefix

{
  __chrome|opera__name: "SuperBlink"
}

if the vendor is chrome or opera, this compiles to:

{
  "name": "SuperBlink"
}

See the original README of wext-manifest-loader package for more details

Bugs

Please file an issue here for bugs, missing documentation, or unexpected behavior.

Linting & TypeScript Config

License

MIT © Abhijith Vijayan

web-extension-starter's People

Contributors

abhijith-vijayan avatar abhijithvijayan avatar aneeshsharma avatar arnaumanyosa avatar aubreypwd avatar dependabot[bot] avatar gumpdev avatar gvozd avatar princesust avatar thaneshr avatar unbyte 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

web-extension-starter's Issues

Browser support

  • Safari: wont end up in the list till it does support Webextensions API

  • Edge: supports this starter in the latest chromium based version only. (not backward compatible) This version of edge supports installing this extension from Chrome store.

  • Other Chromium based browsers: should work on browsers that are based on Chromium 49 and later. Recommended to use the latest version of the browser. These browsers could install published extension from the Chrome store itself.

  • Chrome: From version 49

  • Firefox: From version 52

  • Opera: From version 36

The limitation of backward compatibilty and missing of several APIs in old versions are the reason for setting support from the above mentioned versions.

The extension starter has been tested in all of the above browsers and so added to readme.

Reference: https://caniuse.com/usage-table

Expose environmental variables from .env

I have tried the classic .env with REACT_APP prefix, but it does not work, I guess that is only for react-script.
Does this package it support something similar?
Thanks

master branch: switch to npm, source map error appears

@abhijithvijayan I follow your prompt to delete the relevant files and modify the package.json file:

"build": "npm run build:chrome && npm run build:firefox && npm run build:opera"

Follow readme.md, run:

npm run dev:firefox

But I'm having a small problem,if you know how to fix it please let me know. (I don't know if I'm going to encounter it with yarn),Source map error problems have kept me at bay.

Source map error: Error: NetworkError when attempting to fetch resource.
Resource URL: moz-extension://f3e071f8-a623-4e01-9f41-8c1d7afeec8e/js/contentScript.bundle.js
Source Map URL: browser-polyfill.js.map

I didn't modify travis.yml file because I didn't use 'travis-ci'.

ERROR in ./source/manifest.json

I'm getting this error and there's no reference to what's causing it. manifest.json is basically the same as in the starter.

ERROR in ./source/manifest.json
Module Error (from ./node_modules/wext-manifest-loader/lib/index.js):
Cannot read property 'replace' of undefined

Typo fix

Write Once Run on Any Browser

In readme

Comment here and submit a PR

All colors are inverted?

image

For some reason, all website colors are inverted whenever I activate this boilerplate extension.

Just git pulled and loaded into the latest chrome, no other changes. It goes back to normal when I remove/disable this specific extension and I can't find any styles that lead to this. There's nothing else to attribute this to except this extension being loaded.

What's going on? Any ideas?

optimize webpack output stats

The logs get congested with each build and change

Optimize output stats to show only errors, buildtime, and few other stats

use with react devtools?

In сhrome, extensions not working on extension page(e.g. options.html)
And i dont know a way to make them work

How do you use React Devtools?
Is there some easy way?

I'm trying to use react-devtools-inline for now, and I will share the solution later, if there are no simpler/convenient solutions

option to provide cache busting

As the manifest is generated at runtime, this could be used to inject the scripts source with webpack to manifest.json instead of setting js/background.js as static to prevent caching of scripts which when receives an update.

How to add CSS Modules into ContentScript?

Sorry if it's not the place, probably it's not an issue, but I don't know where to ask.

I use React with Typescript. In ContentScript I load a custom component which is in source/shared/components/MyComponent/MyComponent.tsx

and I create a Scss for it: source/shared/components/MyComponent/MyComponent.scss

I notice that the styling is added in extension/firefox/css/contentScript.css when it's built, but It's not loaded when I run my browser extension.

It's possible to make it work or only inline CSS can work?

Thank you!

Salesforce lightning design system react

When I try to integrate salesforce/design-system-react it's showing babel-preset-env not found. Not sure is it salesforce/design-system-react design system issue or web-extension-starter issue.

Sync-scroll misbehave on long lines

Thanks for the extremely useful plugin!

The sync-scroll feature doesn't play nicely with auto wrap lines on the latex side. For example, I write paragraphs as a very long line since I have screens of different sizes. On the right side, this causes the text in the textarea to be shifted to more than one page.

source mapping to enhance the debugging process

Is it possible to show the actual file contents inside source map without including webpack import. which sometimes difficult to debug

webextension_polyfill__WEBPACK_IMPORTED_MODULE_2___default.a.runtime.onMessage.addListener(function (msg) {
  var action = msg.action;
  console.log("msg::", msg);

  if (action == _message_actions__WEBPACK_IMPORTED_MODULE_7__["default"].IS_SCRIPT_INJECTED) {
    return Promise.resolve(true);
  }
});

[FEAT] Support for Safari Browsers

I have found previous issues (#9 and #11) that Safari uses its proprietary extension format, and web-extension-starter for Safari will not be worked on. I am curious about an updated plan since Safari supports WebExtension from Safari 14. Will there be a Safari branch?

References:

Hot reloading

If there are multiple extension using this boilerplate. Then if I put npm run dev:chrome then all the extension reloaded.

[Migration] support for Manifest v3

Any plans on upgrading this to work with manifest V3? Or a list of manual changes that need to be done? It doesn't seem to work out of the box for V3.

Selenium/WebDriver tests

I have been trying to use your code base to set up a wrapper with Jest and Selenium-Webdriver in order to install the extension in Chrome and Firefox.

In case you would like to add this to your code, please find some starting points here:

https://github.com/slhck/web-extension-selenium-test

Particularly see the test scripts in package.json as well as the files in test/integration.

I've run into a bug with Firefox , where the XPI is not installed, but for Chrome it works fine.

I am not opening a PR at this stage because it is far from complete, but I'm leaving it here as a pointer.

Dynamically generate browser-tailored manifest.json files

Currently there are 3 different manifest.json files for each of the browser.
This was initially aimed to tackle the different fields of manifest.json file that varies between browsers.

Add a better way to generate that according to the build varaint, so that the user needs to keep 1 manifest.json overall.

View the discussion on reddit

issue with sass files with same names imported directly to ts components

WARNING in Conflict: Multiple assets emit different content to the same filename css/styles.css

When styles.scss is imported directly to index.tsx in each of the components, it replaces the initial build file with the following build file causing missing styles.

---Component_A/
   |
   index.tsx
   |
   styles.scss

---Component_B/
   |
   index.tsx
   |
   styles.scss

CRA handles this nice and smooth without any duplication.

What could be right way to dynamically import a file from a npm package into a webpage through content_script?

I have been unsuccessful in trying to import a file from npm package into a web page through content_script. I want to import this file on an action from popup browser action.

To establish the basic setup, I tried importing your emoji-log library. I followed the following steps:

  1. Add new CopyWebpackPlugin([{from: 'node_modules/emoji-log/lib/index.js', to: 'js/emoji-log/lib/index.js'}]), in webpack.config.js
  2. Add following in manifest.json.
"web_accessible_resources": [
  "js/emoji-log/lib/index.js"
],
  1. In content script. (Right now for testing purpose, I am opening it directly. Otherwise I want to open it on an action)
import browser from 'webextension-polyfill';
(async () => {
	const src = browser.extension.getURL("js/emoji-log/lib/index.js");
	await import(src);
})();

I get the following error:

Uncaught (in promise) Error: Cannot find module 'chrome-extension://bkglmbblddekhjgldmkjgadhojbhakjg/js/emoji-log/lib/index.js'

And strangely when I click on the filename, it opens up in the new tab straight away.

What am I missing here? I am stuck on this from quite a few hours.

(These instructions are mostly from here and here)

Migration to ESBuild from Babel

I'm using the React + TypeScript branch and using React in ContentScript,
When I make any change in the react files it takes about 40 seconds until I can see the change in the browser and the page reloaded.
How to make it faster as 40 seconds is too much?

How to import jsx file in ContentScript?

I get

ERROR in ./src/ContentScript/index.ts
Module not found: Error: Can't resolve './FloatingPanel' in 'xxxxx/ContentScript'

截屏2021-06-25 下午8 48 40

/ContentScript/index.ts

import './FloatingPanel';

export {};

/ContentScript/FloatingPanel/index.jsx

import * as React from 'react';
import ReactDOM from 'react-dom';

function FloatingPanel() {
  return <div>aaaa</div>;
}

const mountPointID = 'gamification-floating-ui-root';
document.body.insertAdjacentHTML('afterend', `<div id="${mountPointID}" />`);
ReactDOM.render(<FloatingPanel />, document.querySelector(`#${mountPointID}`));

This will not work.

So, How to render a React widget right into the webpage?

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.