chore: remove webextension-mv3-sw example

This commit is contained in:
Martin Varmuza
2026-02-13 08:04:29 +01:00
committed by martin
parent 8886dc4851
commit 732fe0080f
7 changed files with 0 additions and 164 deletions

View File

@@ -1,24 +0,0 @@
# Web extension manifest V3 example using service worker
`@trezor/connect-webextension` running in a `service worker` and communicating with `@trezor/popup` (which loads core logic) through `chrome.runtime` messages.
Tested in Chrome
## Install
Run the commands below in order to get the webextension ready to be loaded in the browser.
- `yarn`
- `yarn build:libs`
- `yarn workspace @trezor/connect-webextension build`
- `node packages/connect-examples/update-webextensions-sw.js`
This extension is super simple and only reacts to "reload" button.
## Browsers
### Chrome
- Go to chrome://extensions
- Enable developer mode and load unpacked
- Choose `packages/connect-examples/webextension-mv3-sw` directory

View File

@@ -1,15 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<button id="tab">New tab</button>
<button id="get-features" data-testid="get-features">Get features</button>
<button id="get-address" data-testid="get-address">Get Address</button>
<div id="result"></div>
<script src="./connect-manager.js" type="module"></script>
</body>
</html>

View File

@@ -1,41 +0,0 @@
// This JavaScript code is running in the connect-manager.html tab of the webextension
// and it communicates with the service worker when it needs something from Trezor device.
// There are different ways to achieve message passing from the tab with the service-worker,
// for more info: https://developer.chrome.com/docs/extensions/develop/concepts/messaging
document.getElementById('get-address').addEventListener('click', () => {
// Send a message to the background script (service worker) with the action 'getAddress'
chrome.runtime.sendMessage({ action: 'getAddress' }, response => {
// Check if the response indicates success
if (response.success) {
console.info(response); // Log the successful response to the console
// Display the response in the 'result' element on the page
document.getElementById('result').innerText = JSON.stringify(response);
} else {
console.error(response); // Log the error response to the console
// Display an error message in the 'result' element on the page
document.getElementById('result').innerText = 'Error: ' + response.error;
}
});
});
document.getElementById('get-features').addEventListener('click', () => {
// Send a message to the background script (service worker) with the action 'getFeatures'
chrome.runtime.sendMessage({ action: 'getFeatures' }, response => {
// Check if the response indicates success
if (response.success) {
console.info(response); // Log the successful response to the console
// Display the response in the 'result' element on the page
document.getElementById('result').innerText = JSON.stringify(response);
} else {
console.error(response); // Log the error response to the console
// Display an error message in the 'result' element on the page
document.getElementById('result').innerText = 'Error: ' + response.error;
}
});
});
const newTabButton = document.getElementById('tab');
newTabButton.addEventListener('click', () => {
chrome.tabs.create({ url: 'connect-manager.html' });
});

View File

@@ -1,19 +0,0 @@
{
"name": "@trezor/connect web extension mv3 example",
"version": "1.0.0",
"manifest_version": 3,
"action": {
"default_popup": "popup.html"
},
"background": {
"service_worker": "serviceWorker.js"
},
"permissions": ["scripting"],
"host_permissions": [
"*://connect.trezor.io/9/*",
"*://suite.corp.sldev.cz/*",
"*://localhost/*",
"*://staging-connect.trezor.io/*",
"*://dev.suite.sldev.cz/*"
]
}

View File

@@ -1,12 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<button id="tab">Connect manager</button>
<script src="./popup.js" type="module"></script>
</body>
</html>

View File

@@ -1,8 +0,0 @@
document.addEventListener('DOMContentLoaded', () => {
const newTabButton = document.getElementById('tab');
if (newTabButton) {
newTabButton.addEventListener('click', () => {
chrome.tabs.create({ url: 'connect-manager.html' });
});
}
});

View File

@@ -1,45 +0,0 @@
// Dynamic script loading to import the Trezor Connect script, making its functions available in this service worker.
// This is designed to work within the service-worker context, which does not support ES6 modules natively.
importScripts('vendor/trezor-connect-webextension.js');
// URL of the Trezor Connect
const connectSrc = 'https://connect.trezor.io/9/';
chrome.runtime.onInstalled.addListener(details => {
console.log('details', details);
// Initialize Trezor Connect with the provided manifest and settings
TrezorConnect.init({
manifest: {
email: 'meow@example.com',
appName: 'Trezor Connect Example',
appUrl: 'https://yourAppUrl.com/',
},
transports: ['BridgeTransport', 'WebUsbTransport'], // Transport protocols to be used
connectSrc,
});
// Event listener for messages from other parts of the extension
// This code will depend on how you handle the communication between different parts of your webextension.
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'getAddress') {
TrezorConnect.getAddress({
showOnTrezor: true,
path: "m/49'/0'/0'/0/0",
coin: 'btc',
}).then(res => {
sendResponse(res); // Send the response back to the sender
});
// Return true to indicate you want to send a response asynchronously
return true;
} else if (message.action === 'getFeatures') {
TrezorConnect.getFeatures().then(res => {
sendResponse(res); // Send the response back to the sender
});
// Return true to indicate you want to send a response asynchronously
return true;
}
});
});