This guide will walk you through setting up Reflux and creating your first plugin.
npm install @nightnetwork/refluxReflux requires the following peer dependencies:
@mercuryworkshop/bare-mux- BareMux transport multiplexer- A base transport (e.g.,
@mercuryworkshop/epoxy-transportor@mercuryworkshop/libcurl-transport)
npm install @mercuryworkshop/bare-mux @mercuryworkshop/epoxy-transportInclude the required scripts in your HTML:
<!DOCTYPE html>
<html>
<head>
<title>My Reflux App</title>
<script src="/baremux/index.js"></script>
<script src="/reflux/api.js"></script>
</head>
<body>
<script src="app.js"></script>
</body>
</html>// Initialize BareMux connection
const connection = new window.BareMux.BareMuxConnection("/baremux/worker.js");
// Set Reflux as the transport wrapper
await connection.setTransport(
"/reflux/index.mjs",
[
{
base: "/epoxy/index.mjs",
wisp: "wss://your-wisp-server.com/wisp/"
}
]
);
console.log("Reflux transport initialized!");// Get RefluxAPI class
const RefluxAPIClass = window.RefluxAPIModule.RefluxAPI;
// Create instance
const api = new RefluxAPIClass();
console.log("Reflux API ready!");Let's create a simple plugin that logs information about every page visit:
// Define the plugin
const myFirstPlugin = {
name: "com.myapp.logger",
sites: ["*"], // Run on all sites
function: `
/* @browser */
console.log('Page loaded:', url);
console.log('Plugin:', pluginName);
console.log('Title:', document.title);
/* @/browser */
`
};
// Add the plugin
await api.addPlugin(myFirstPlugin);
// Enable the plugin
await api.enablePlugin("com.myapp.logger");
console.log("Plugin installed and enabled!");Use reverse domain notation for plugin names:
com.mycompany.pluginnameorg.project.featureio.github.username.plugin
This prevents naming conflicts.
- Navigate to any website through your proxy
- Open the browser console (F12)
- You should see the log messages from your plugin!
const plugins = await api.listPlugins();
console.log("Installed plugins:", plugins);await api.disablePlugin("com.myapp.logger");
console.log("Plugin disabled");await api.enablePlugin("com.myapp.logger");
console.log("Plugin enabled");await api.removePlugin("com.myapp.logger");
console.log("Plugin removed");const enabled = await api.getEnabledPlugins();
console.log("Enabled plugins:", enabled);Here's a complete working example:
(async () => {
// 1. Initialize BareMux with Reflux
const connection = new window.BareMux.BareMuxConnection("/baremux/worker.js");
await connection.setTransport("/reflux/index.mjs", [{
base: "/epoxy/index.mjs",
wisp: "wss://wisp-server.com/wisp/"
}]);
// 2. Create Reflux API
const api = new window.RefluxAPIModule.RefluxAPI();
// 3. Add a visual indicator plugin
await api.addPlugin({
name: "com.example.indicator",
sites: ["*"],
function: `
/* @browser */
const banner = document.createElement('div');
banner.textContent = '🚀 Reflux Active';
banner.style.cssText =
'position: fixed; top: 0; right: 0; ' +
'background: #0066cc; color: white; ' +
'padding: 8px 16px; z-index: 999999; ' +
'font-family: monospace; font-size: 12px;';
document.body.appendChild(banner);
/* @/browser */
`
});
// 4. Enable the plugin
await api.enablePlugin("com.example.indicator");
console.log("✅ Reflux is ready!");
})();-
Check if plugin is enabled:
const enabled = await api.getEnabledPlugins(); console.log("Enabled plugins:", enabled);
-
Verify plugin was added:
const plugins = await api.listPlugins(); console.log("All plugins:", plugins);
-
Check site matching:
// If your plugin targets specific sites, make sure the URL matches await api.updatePluginSites("plugin-name", ["example.com", "*.example.com"]);
- "RefluxAPIModule not found": Make sure
/reflux/api.jsis loaded before your script - "Plugin has no code": Ensure the
functionproperty is not empty - Storage errors: Check browser console for IndexedDB/LocalForage errors
- Avoid heavy computations in browser-side plugin code
- Use site-specific targeting instead of
["*"]when possible - Test plugins individually to identify problematic code
- HTML Modification Guide - Learn to modify website content
- WebSocket Middleware - Intercept WebSocket traffic
- API Reference - Complete API documentation