Building and Starting the Project
Prerequisites
Ensure you have Docker installed on your system to build and run the project. You will also need Node.js and npm to manage dependencies.
Step-by-Step Guide
Clone the repository
Navigate to your desired directory and clone the repository:git clone https://github.com/screenly/chrome-extension.git cd chrome-extension
Install dependencies
Run the following command to install project dependencies:npm install
Build the project using Docker
The extension is built using webpack. Use the following Docker command to build the project:docker compose up --build
Load the unpacked extension in Chrome
After building, load the content of thedist/
folder as an unpacked extension in Chrome. You can do this by navigating tochrome://extensions/
, enabling “Developer mode”, and clicking on “Load unpacked”.Development Workflow
As you make changes to the code, the extension is automatically rebuilt. You can simply refresh the extensions page in Chrome to see the changes.
Additional Information
API Call Example
Insrc/assets/js/main.mjs
, there is a function to call APIs. Here is an example of how it is defined:function callApi(method, url, data=undefined, token=undefined) { let init = { method: method, headers: { 'Content-Type': 'application/json', 'Prefer': 'return=representation', } }; if (data !== undefined && data !== null) { init.body = JSON.stringify(data); } if (token) { init.headers['Authorization'] = `Token ${token}`; } return fetch(url, init) .then(response => { if (!(response.status >= 200 && response.status < 300)) { throw response; } }); }
Popup Initialization
The popup is initialized insrc/assets/js/boot-popup.mjs
. Here is the relevant code:'use strict'; import {initPopup} from "./popup.mjs"; await initPopup();
Testing
To run tests, use the following command defined in thepackage.json
:npm run test
Refer to the README.md for further instructions on deployment and packaging.