Electron app example
Quick installation guide to setup the BetterBugs Web SDK widget for your Electron applications.
How to install BetterBugs Web SDK in Electron apps
Check out the GitHub repo for the Electron example app covered here.
Here are the steps for it:
Generate an API key from Project Settings
Log in to your BetterBugs dashboard and generate an API key from Project Settings. You’ll need it to initialize the SDK in the following steps.
Install BetterBugs Web SDK: Add CDN script to the HTML head tag in your app
Add the following CDN script in the Electron app’s HTML head:
<html>
<head>
<!-- Put this in the HTML head tag -->
<script src="https://cdn.jsdelivr.net/npm/@betterbugs/web-sdk@latest/index.js"></script>
</head>
</html>
We’ve used the CDN script here for the demo setup. You can also install the SDK files in your application using npm or yarn and modify the JavaScript syntax accordingly.
npm install @betterbugs/web-sdk
Configure Electron app for BetterBugs SDK: Add the following code to TypeScript src/main.ts file
Add the following code inside app.whenReady()
in your main.ts
file, before creating the application window, to configure a custom screen capture handler using session.defaultSession.setDisplayMediaRequestHandler
You can replace the entire file code with the below code in the TypeScript file located at src/main.ts.
import { app, BrowserWindow, session, desktopCapturer } from "electron";
// Wait for the app to be ready before creating the window
app.whenReady().then(() => {
// Configure session before creating window
session.defaultSession.setDisplayMediaRequestHandler(
(request, callback) => {
desktopCapturer.getSources({ types: ["screen"] }).then((sources) => {
callback({ video: sources[0], audio: "loopback" });
});
},
{ useSystemPicker: false }
);
createWindow();
});
function createWindow() {
const mainWindow = new BrowserWindow();
// Load the index.html file
mainWindow.loadFile("index.html");
mainWindow.setFullScreen(true);
}
Initialize the SDK (with default UI)
Next, add the following JavaScript code snippet to your HTML file to initialize the SDK widget. Make sure to add your project API key in the function:
<!-- BetterBugs SDK initialization -->
<script>
document.addEventListener("DOMContentLoaded", () => {
window.bb = new Betterbugs({
// Replace with your BetterBugs Project API Key
apiKey: "YOUR-API-KEY-GOES-HERE",
});
});
</script>
Customize the SDK widget UI (Optional)
You can customize the SDK with your brand colors and design from the initialization function:
<!-- BetterBugs SDK initialization -->
<script>
document.addEventListener("DOMContentLoaded", () => {
window.bb = new Betterbugs({
// Replace with your BetterBugs Project API Key
apiKey: "YOUR-API-KEY-GOES-HERE",
// UI Customization Examples
position: { top: "20px", right: "20px" },
styles: {
primaryColor: "#e41c38",
primaryTextColor: "#fff",
theme: "light",
},
});
});
</script>
The Web SDK widget should be available at the bottom right side of your app screen (with the default UI).
NOTE: If the widget is not visible,
Please check if you’ve correctly entered the API key.
Check for the console errors, if any.
If you’re still stuck, try running your dev server in the INCOGNITO mode of your web browser.
Some ad blockers or extensions may also prevent the Widget from running. Please turn them off and try running the application again. It should work fine.
You're good to go.
Last updated
Was this helpful?