接收端不存在:sendMessage 后台弹出

发布于 2025-01-11 03:39:20 字数 1437 浏览 0 评论 0原文

我搜索了 1 个小时的答案,但没有适合我的问题。如果这是一个常见问题,我深表歉意。所以我有一个弹出脚本必须等待来自后台的消息。但我总是收到这个错误

错误:无法建立连接。接收端不存在。

这是我的弹出窗口

$( document ).ready(function()
{   
    chrome.extension.getBackgroundPage().download(true, "test");
    chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
       console.log(request, sender, sendResponse);
    });    
});

,这是我的背景,它是我的 http 请求的一部分

if(this.readyState ==3 && this.status ==200)
    {            
        chrome.tabs.query({active: true, currentWindow: true},function(tabs) {
            chrome.tabs.sendMessage(tabs[0].id, "Loading", function(response) {
                console.log(response);
            });
          });
    }

,这是我的清单

 `{

    
"name": "My extension axel",
"version": "1.0",
"description": "first extension",

"icons":{
    "16":"/images/ytDownloader_image_16.png",
    "48":"/images/ytDownloader_image_48.png",
    "128":"/images/ytDownloader_image_128.png"
},

"permissions": [
    "activeTab",
    "tabs",
    "webRequest",
    "webNavigation",
    "management",
    "http://*/*",
    "https://*/*",
    "*://*.google.com/"
],
"browser_action": {
    "default_popup" :"popup.html"
  },


"background":{
    "scripts":["/js/jquery-3.5.1.min.js","background.js"],
    "persistent": true
},
"manifest_version": 2
}`

请帮助我:)

I searched for 1 hour my answer but nothing that fits my issue. I apolagize if it was a common problem. So I have one popup script that have to wait a message from the Background. But I always get this error

Error : Could not establish connection. Receiving end does not exist.

here is my popup

$( document ).ready(function()
{   
    chrome.extension.getBackgroundPage().download(true, "test");
    chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
       console.log(request, sender, sendResponse);
    });    
});

and here is my background which is a part of my http request

if(this.readyState ==3 && this.status ==200)
    {            
        chrome.tabs.query({active: true, currentWindow: true},function(tabs) {
            chrome.tabs.sendMessage(tabs[0].id, "Loading", function(response) {
                console.log(response);
            });
          });
    }

and here is my manifest

 `{

    
"name": "My extension axel",
"version": "1.0",
"description": "first extension",

"icons":{
    "16":"/images/ytDownloader_image_16.png",
    "48":"/images/ytDownloader_image_48.png",
    "128":"/images/ytDownloader_image_128.png"
},

"permissions": [
    "activeTab",
    "tabs",
    "webRequest",
    "webNavigation",
    "management",
    "http://*/*",
    "https://*/*",
    "*://*.google.com/"
],
"browser_action": {
    "default_popup" :"popup.html"
  },


"background":{
    "scripts":["/js/jquery-3.5.1.min.js","background.js"],
    "persistent": true
},
"manifest_version": 2
}`

Please help me :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文