Я пытаюсь отправить некоторые данные из моего веб-приложения в расширение Chrome (как это описано в документации Google ), но у меня появляется ошибка: Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
Мой контент-скрипт:
chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
if (sender.url == blocklistedWebsite)
return; // don't allow this web page access
if (request.openUrlInEditor)
openUrl(request.openUrlInEditor);
});
И это мой манифест:
{
"name": "test-extension",
"version": "0.0.1",
"manifest_version": 2,
"background": {
"scripts": ["src/bg/background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["http://localhost/*"],
"js": ["src/inject/inject.js"]
}
],
"externally_connectable": {
"ids": ["abcdefghijklmnoabcdefhijklmnoabc"],
"matches": ["http://localhost/*"],
"accepts_tls_channel_id": false
}
}
И тестовая страница, на которую я пытаюсь отправить данные:
<body>
<button onclick="processData()">Send data to extension</button>
</body>
<script>
function processData() {
/* ... */
// The ID of the extension we want to talk to.
var editorExtensionId = "abcdefghijklmnoabcdefhijklmnoabc";
// Make a simple request:
chrome.runtime.sendMessage(
editorExtensionId,
{ openUrlInEditor: 'https://google.com' },
function(response) {
if (!response.success) handleError(url);
}
);
}
</script>