Important Notice: We're experiencing email notification issues. If you've posted a question in the community forums recently, please check your profile manually for responses while we're working to fix this.

On Monday the 3rd of March, around 5pm UTC (9am PT) users may experience a brief period of downtime while one of our underlying services is under maintenance.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

I want to write an addon firewall but it fails

more options
#!/bin/bash

# Verzeichnis erstellen
mkdir FoxyAddOnFirewall
cd FoxyAddOnFirewall || exit

# package.json erstellen
cat <<EOF > package.json
{
  "title": "Foxy AddOn Firewall",
  "name": "foxy-addon-firewall",
  "description": "A Firefox addon to control internet access for other addons",
  "author": "Your Name",
  "version": "1.0.0",
  "license": "MIT"
}
EOF

# background.js erstellen
cat <<EOF > background.js
var permissionManager = Components.classes["@mozilla.org/permissionmanager;1"]
                        .getService(Components.interfaces.nsIPermissionManager);

// Addon-Liste abrufen
function getAllAddons() {
    var {AddonManager} = Components.utils.import("resource://gre/modules/AddonManager.jsm", {});
    return new Promise(function(resolve, reject) {
        AddonManager.getAllAddons(function(addons) {
            resolve(addons);
        });
    });
}

// GUI aktualisieren
function updateUI() {
    getAllAddons().then(function(addons) {
        var addonList = document.getElementById("addon-list");
        addonList.innerHTML = ""; // Zurücksetzen der Liste

        addons.forEach(function(addon) {
            var listItem = document.createElement("li");
            listItem.textContent = addon.name;
            
            var blockButton = document.createElement("button");
            blockButton.textContent = "Block";
            blockButton.addEventListener("click", function() {
                blockInternetAccessForAddon(addon);
            });

            listItem.appendChild(blockButton);
            addonList.appendChild(listItem);
        });
    });
}

// Internetzugriff für ein bestimmtes Addon blockieren
function blockInternetAccessForAddon(addon) {
    var host = addon.getResourceURI("").host;
    permissionManager.remove(host, "allAccess");
    console.log("Internetzugriff für " + addon.name + " wurde blockiert.");
}

document.addEventListener("DOMContentLoaded", function() {
    updateUI(); // GUI beim Laden der Seite aktualisieren
});
EOF

# index.html erstellen
cat <<EOF > index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Foxy AddOn Firewall</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <h1>Foxy AddOn Firewall</h1>
  <p>Welcome to Foxy AddOn Firewall!</p>

  <h2>Installed Addons:</h2>
  <ul id="addon-list">
    <!-- Addon-Liste wird hier eingefügt -->
  </ul>

  <script src="background.js"></script>
</body>
</html>
EOF

# style.css erstellen
cat <<EOF > style.css
body {
  font-family: Arial, sans-serif;
  background-color: #f0f0f0;
  text-align: center;
}

h1 {
  color: #007bff;
}

h2 {
  margin-top: 20px;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  margin-bottom: 10px;
}

button {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}
EOF

# manifest.json erstellen
cat <<EOF > manifest.json
{
  "manifest_version": 2,
  "name": "Foxy AddOn Firewall",
  "version": "1.0",
  "description": "A Firefox addon to control internet access for other addons",
  "icons": {
    "48": "icon.png"
  },
  "permissions": [
    "management"
  ],
  "browser_action": {
    "default_popup": "index.html",
    "default_icon": "icon.png"
  }
}
EOF

# Icon herunterladen
wget -O icon.png "https://img.icons8.com/ios-filled/50/000000/firewall.png"

# Installationsanweisungen anzeigen
echo "FoxyAddOnFirewall wurde erfolgreich initialisiert!"
echo "Um das Addon in Firefox zu installieren:"
echo "1. Öffnen Sie Firefox und geben Sie 'about:debugging' in die Adressleiste ein."
echo "2. Klicken Sie auf 'Dieses Firefox installieren' unter 'Temporäre Add-ons laden'."
echo "3. Navigieren Sie zum Verzeichnis 'FoxyAddOnFirewall' und wählen Sie die 'manifest.json' Datei aus."
echo "4. Das Addon wird nun installiert und kann verwendet werden."
<pre><nowiki>#!/bin/bash # Verzeichnis erstellen mkdir FoxyAddOnFirewall cd FoxyAddOnFirewall || exit # package.json erstellen cat <<EOF > package.json { "title": "Foxy AddOn Firewall", "name": "foxy-addon-firewall", "description": "A Firefox addon to control internet access for other addons", "author": "Your Name", "version": "1.0.0", "license": "MIT" } EOF # background.js erstellen cat <<EOF > background.js var permissionManager = Components.classes["@mozilla.org/permissionmanager;1"] .getService(Components.interfaces.nsIPermissionManager); // Addon-Liste abrufen function getAllAddons() { var {AddonManager} = Components.utils.import("resource://gre/modules/AddonManager.jsm", {}); return new Promise(function(resolve, reject) { AddonManager.getAllAddons(function(addons) { resolve(addons); }); }); } // GUI aktualisieren function updateUI() { getAllAddons().then(function(addons) { var addonList = document.getElementById("addon-list"); addonList.innerHTML = ""; // Zurücksetzen der Liste addons.forEach(function(addon) { var listItem = document.createElement("li"); listItem.textContent = addon.name; var blockButton = document.createElement("button"); blockButton.textContent = "Block"; blockButton.addEventListener("click", function() { blockInternetAccessForAddon(addon); }); listItem.appendChild(blockButton); addonList.appendChild(listItem); }); }); } // Internetzugriff für ein bestimmtes Addon blockieren function blockInternetAccessForAddon(addon) { var host = addon.getResourceURI("").host; permissionManager.remove(host, "allAccess"); console.log("Internetzugriff für " + addon.name + " wurde blockiert."); } document.addEventListener("DOMContentLoaded", function() { updateUI(); // GUI beim Laden der Seite aktualisieren }); EOF # index.html erstellen cat <<EOF > index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Foxy AddOn Firewall</title> <link rel="stylesheet" href="style.css"> </head> <body> <h1>Foxy AddOn Firewall</h1> <p>Welcome to Foxy AddOn Firewall!</p> <h2>Installed Addons:</h2> <ul id="addon-list"> <!-- Addon-Liste wird hier eingefügt --> </ul> <script src="background.js"></script> </body> </html> EOF # style.css erstellen cat <<EOF > style.css body { font-family: Arial, sans-serif; background-color: #f0f0f0; text-align: center; } h1 { color: #007bff; } h2 { margin-top: 20px; } ul { list-style-type: none; padding: 0; } li { margin-bottom: 10px; } button { background-color: #007bff; color: white; border: none; padding: 5px 10px; border-radius: 5px; cursor: pointer; } button:hover { background-color: #0056b3; } EOF # manifest.json erstellen cat <<EOF > manifest.json { "manifest_version": 2, "name": "Foxy AddOn Firewall", "version": "1.0", "description": "A Firefox addon to control internet access for other addons", "icons": { "48": "icon.png" }, "permissions": [ "management" ], "browser_action": { "default_popup": "index.html", "default_icon": "icon.png" } } EOF # Icon herunterladen wget -O icon.png "https://img.icons8.com/ios-filled/50/000000/firewall.png" # Installationsanweisungen anzeigen echo "FoxyAddOnFirewall wurde erfolgreich initialisiert!" echo "Um das Addon in Firefox zu installieren:" echo "1. Öffnen Sie Firefox und geben Sie 'about:debugging' in die Adressleiste ein." echo "2. Klicken Sie auf 'Dieses Firefox installieren' unter 'Temporäre Add-ons laden'." echo "3. Navigieren Sie zum Verzeichnis 'FoxyAddOnFirewall' und wählen Sie die 'manifest.json' Datei aus." echo "4. Das Addon wird nun installiert und kann verwendet werden."</nowiki></pre>

Modified by cor-el

All Replies (1)

more options

Hi, this forum focuses on end user questions. Could you try the Add-on Development forum here:

https://discourse.mozilla.org/c/add-ons/development/108