Page 1 of 1

Safari-Web-Erweiterung empfängt keine Nachrichten von einer Webseite auf dem Hintergrund

Posted: 09 Apr 2025, 01:10
by Anonymous
Ich arbeite an der Asafri-Web-Erweiterung, ich habe zuerst eine Chromerweiterung erstellt und dann den Befehl xcrun safari-Web-Extensionskonverter/Pfad/zu/erweitert in Safari umwandeln. HTML -Datei wird verwendet

Code: Select all

 browser.runtime.sendMessage(extensionId
..) zum Senden
sendet

Code: Select all

Extension Installation Checker
This page tests if your extension is installed by sending a message to it.

Check for Extension


document.getElementById('checkButton').addEventListener('click', checkExtension);

async function checkExtension() {

const extensionId = "I USED MY EXTENSION ID HERE ";
const resultDiv = document.getElementById('result');

resultDiv.textContent = "Checking...";
resultDiv.className = "";

try {
// Try to send message to extension
const response = await browser.runtime.sendMessage(extensionId, {
type: "PING",
message: "Are you there?"
});

if (response) {
resultDiv.textContent = `✅ Extension is installed! Response: ${JSON.stringify(response)}`;
resultDiv.className = "installed";
} else {
resultDiv.textContent = "⚠️ Extension may be installed but didn't respond";
resultDiv.className = "not-installed";
}
} catch (error) {
resultDiv.textContent = `❌ Extension not detected or error: ${error.message}`;
resultDiv.className = "not-installed";
console.error("Error:", error);
}
}



< /code>
Auf dem Hintergrund.js Ich höre die Nachricht mit < /p>
anbrowser.runtime.onMessageExternal.addListener((request, sender, sendResponse) => {
if (request.type === "PING") {
sendResponse({ status: "OK", version: "1.0" });
}
});

< /code>
Und hier ist, was mein Manifest aussieht < /p>
{
"manifest_version": 3,
"name": "__MSG_extension_name__",
"description": "__MSG_extension_description__",
"version": "1.0",
"default_locale": "en",

"icons": {
"48": "images/icon-48.png",
"96": "images/icon-96.png",
"128": "images/icon-128.png",
"256": "images/icon-256.png",
"512": "images/icon-512.png"
},

"background": {
"service_worker": "background.js"
},

"permissions": [
"tabs"
],

"host_permissions": [
"https://*.ngrok-free.app/*"
],

"externally_connectable": {
"matches": [
"https://8e85-91-201-165-34.ngrok-free.app/*"
]
},

"content_scripts": [
{
"matches": ["https://*.ngrok-free.app/*"],
"js": ["content.js"]
}
]
}

Mein Problem ist, dass ich die Nachricht auf dem Hintergrund nie empfange Die Kommunikation zwischen der Erweiterung und der Webseite funktioniert nicht, wie kann ich dies