Step-by-Step Guide - Opera GX Extensions
This guide will walk you through the process of creating an Opera GX extension using Manifest V3.
This guide will help you create a comprehensive Opera GX extension that includes a popup interface, sidebar, options page, and service worker script. Follow these steps to build, test, and refine your extension.
Project Structure
Here’s what your project structure will look like:
my-opera-gx-extension/
│
├── manifest.json // Manifest file defining your extension
├── popup.html // Popup interface
├── sidebar.html // Sidebar content
├── options.html // Options page
├── scripts/
│ ├── popup.js // JavaScript for the popup
│ ├── sidebar.js // JavaScript for the sidebar
│ ├── options.js // JavaScript for the options page
│ └── service-worker.js // Service worker script
├── styles/
│ ├── popup.css // Styles for the popup
│ ├── sidebar.css // Styles for the sidebar
│ ├── options.css // Styles for the options page
├── icons/
│ ├── icon16.png // Icon for the toolbar
│ ├── icon48.png // Icon for extension listing
│ ├── icon128.png // Icon for extension details
Create the Manifest File
- Create
manifest.json
in your project folder. - Add the following content:
manifest.json
{
"manifest_version": 3,
"name": "Advanced GX Extension",
"version": "1.0",
"description": "An advanced Opera GX extension with sidebar, options page, and service worker.",
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
}
},
"permissions": [
"storage",
"tabs",
"activeTab"
],
"background": {
"service_worker": "scripts/service-worker.js"
},
"sidebar_action": {
"default_page": "sidebar.html",
"default_icon": "icons/icon48.png",
"default_title": "GX Sidebar"
},
"options_page": "options.html",
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
}
}
Add a Popup Interface
- Create
popup.html
: - Add styles in
styles/popup.css
: - Add JavaScript in
scripts/popup.js
:
popup.html
styles/popup.css
scripts/popup.js
<!DOCTYPE html>
<html>
<head>
<title>GX Popup</title>
<link rel="stylesheet" href="styles/popup.css">
</head>
<body>
<h1>Welcome to GX!</h1>
<button id="open-sidebar">Open Sidebar</button>
<script src="scripts/popup.js"></script>
</body>
</html>
Add a Sidebar
- Create
sidebar.html
: - Add styles in
styles/sidebar.css
: - Add JavaScript in
scripts/sidebar.js
:
sidebar.html
styles/sidebar.css
scripts/sidebar.js
<!DOCTYPE html>
<html>
<head>
<title>GX Sidebar</title>
<link rel="stylesheet" href="styles/sidebar.css">
</head>
<body>
<h2>GX Sidebar</h2>
<p>This is your custom sidebar.</p>
<script src="scripts/sidebar.js"></script>
</body>
</html>
Add an Options Page
- Create
options.html
: - Add styles in
styles/options.css
: - Add JavaScript in
scripts/options.js
:
options.html
styles/options.css
scripts/options.js
<!DOCTYPE html>
<html>
<head>
<title>GX Options</title>
<link rel="stylesheet" href="styles/options.css">
</head>
<body>
<h2>Extension Options</h2>
<label for="theme">Choose Theme:</label>
<select id="theme">
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
<script src="scripts/options.js"></script>
</body>
</html>
Add a Service Worker
- Create
scripts/service-worker.js
:
scripts/service-worker.js
chrome.runtime.onInstalled.addListener(() => {
console.log('Extension installed!');
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'ping') {
sendResponse({ response: 'pong' });
}
});
Test and Debug
- Load the Extension:
- Go to
opera://extensions
. - Enable Developer Mode.
- Click "Load unpacked" and select your project folder.
- Go to
- Test Features:
- Click the toolbar icon to test the popup.
- Open the sidebar from the popup or extensions menu.
- Visit
opera://extensions-options
to test the options page.
- Debug:
- Use the developer tools (
Ctrl+Shift+I
) to inspect elements and view console logs.
- Use the developer tools (
Package and Publish
- Package:
- Zip the project folder.
- Publish:
- Submit to the Opera Add-ons store.
Congratulations! 🎉 You've created a fully functional Opera GX extension with a popup, sidebar, options page, and service worker. Explore more GX-specific APIs to enhance your extension further.
Please support us by disabling your ad blocker.