chrome extension converted to safari, chrome.runtime.sendMessage does not work on iOS

121 views Asked by At

My Chrome extension runs fine on Chrome, but when I use the following command to run it on Safari, I find that the result returned by chrome.runtime.sendMessage is always Undefined.

xcrun safari-web-extension-converter  --app-name MySafariTest dist

The following is my code content.js:

async test() {
        return chrome.runtime.sendMessage({
            method: "test"
        })
    }
let result = await this.test()
// result is always undefined

background.js:

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
    sendResponse("test123")
});

I want to know if there is any way to make the content script and background script of Chrome communicate normally in Safari?

1

There are 1 answers

1
李志博 On

I have solved this problem by myself. It's not that the browser doesn't support it, but another line of code previously running in the background script caused an error due to lack of browser support, resulting in the failure of loading the background script and inability to receive messages.