This project builds a web extension
You will need to add a backend for Freighter to connect to. You can configure
this by adding an .env
file at the path extension/.env
.
Inside this file, you can configure a backend by setting a value for the global
variable INDEXER_URL
. For example, to connect to the production backend, in
your .env
file, you can add the line
INDEXER_URL=https://freighter-backend.stellar.org/api/v1
.
To connect to a local instance of the backend, just swap out the value in
INDEXER_URL
.
We will compile the code for the extension and then load this package into your browser.
Run
yarn build
You may also choose to enable some experimental features by alternatively running
yarn build:experimental
To install on Chrome:
-
In Chrome, navigate to
chrome://extensions/
. -
Toggle
Developer mode
to the ON position in the top right corner -
You will now see a button in the top left titled
Load Unpacked
-
Click
Load Unpacked
and it will open your file system. -
Navigate to this folder (
/extension
) and click thebuild
folder. HitSelect
. You should now see an icon for Freighter in Chrome.
To install on Firefox:
-
In Firefox, navigate to about:debugging#/runtime/this-firefox
-
Click
Load Temporary Add-On
-
Navigate to this folder (
/extension
) and open thebuild
folder and findmanifest.json
. HitSelect
. You should now see an icon for Freighter in Firefox
When we build for the app store, we will minify our code and enable some security guardrails. In order to do that, run
yarn build:production
Note that when you build using this setting and install locally, you will NOT be able to connect to it using a dev server (mentioned in the next stop)
Next we'll spin up a dev environment. Here, you can access the popup
in your
browser, so you can make edits with the benefit of hot reloads. This dev
environment will be able to make calls to the installed version of the
extension, so it has all the capabilites of the popup
inside the extension.
NOTE: This dev environment only works for the popup
Changes to background
and content script
will still require a production
build using yarn build
, followed by reloading the extension in Chrome.
- Start a local dev server by running
yarn start
You should be able to access the Popup by going to localhost:9000/
You can also set the experimental
flag to true by running
yarn start:experimental
This will enable some features hidden by the experimental
feature flag that
are still under development.
WARNING: running the intergration tests will clear the apps data
Steps:
- Build the extension in experimental mode
yarn build:experimental
- Start the dev server
yarn start
- Go to the integration tests route
localhost:9000/#/integration-test
Errors, if any, will be in the console logs.
This app has 3 main components that are named using extension nomenclature. All
of these are located in the src/
folder:
-
The UI that appears when you click on the extension in your browser. This code also controls the fullscreen authentiction flow and any popups triggered by the extension. This is all controlled by one React app. In web extension parlance, this is called the
popup
and is therefore located insrc/popup
. -
The "backend" service. We want to do things like account creation and store sensitive data, like public keys, in a secure place away from the
popup
and away from thecontent script
. We want this service to be a standalone entity that these other 2 can make requests to and receive only what the backend sees fit. In web extension terms, this is known as thebackground
script and is instantiated bypublic/background
. The code is located insrc/background
.This script is run by the extension on browser starts and continues running, storing data and listening/responding to messages from
popup
andcontent script
, and only terminates on browser close (or extension uninstall/reload). It is run in a headless browser, so it has access to all Web APIs. It also has accessible dev tools, which can be reached by going tochrome://extensions/
orabout:debugging#/runtime/this-firefox
and clickingservice worker
-
The
content script
that allows external sites to send and receive messages tobackground
. Using an event listener, it waits for an application to attempt to communicate using@stellar/freighter-api
(under the hood,window.postMessage
). Once it picks up a message and determines that this fromfreighter-api
, it sends the message ontobackground
.