Emi*_*lio 30 linux postgresql node.js google-chrome-devtools sequelize.js
我最近卸载并重新安装了Postgres10.然后我去运行一个Node/Express/React应用程序,它依赖于连接到Postgres数据库(并使用Sequelize与它通信).
最初它无法连接到数据库.我意识到卸载过程删除了我的旧数据库,所以然后我重新创建了一个新的,具有该应用程序连接的名称.然后,当我重新启动应用程序(服务器和客户端)时,与数据库的前端交互再次正常工作 - 编写新用户并读取它们以进行身份验证等.
但是,在应用程序的每个页面加载时,我现在在Chrome开发工具控制台中出现以下错误:
未选中runtime.lastError:无法建立连接.接收端不存在
此错误引用localhost /:1.当我将鼠标悬停在此状态时,它会显示http:// localhost:3000 /,我在浏览器中查看应用程序的地址.
任何人都知道发生了什么事?我发现提出这个错误的大多数其他线程似乎与尝试开发Chrome扩展程序的人有关,即便如此,他们往往只有很少的回复.
小智 37
我在开发 Chrome 扩展时发现了同样的问题。我终于找到了关键问题。
未经检查的 runtime.lastError: 无法建立连接。接收端不存在
关键问题是,当background.js
通过 chrome.tabs.sendMessage 向活动选项卡发送消息时,content.js
页面上的 未准备好或未重新加载。调试的时候。我们必须确保 content.js 处于活动状态。并且它不能是没有刷新的页面,旧页面不会更新你的js本身
这是我的代码:
//background.js
chrome.tabs.query({active: true, currentWindow: true},function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
console.log(response);
});
});
//content.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
console.log(request, sender, sendResponse);
sendResponse('?????????'+JSON.stringify("request"));
});
Run Code Online (Sandbox Code Playgroud)
fre*_*erj 27
我得到了完全相同的错误(除了我的应用程序没有后端和React前端),我发现它不是来自我的应用程序,它实际上来自"视频速度控制器"Chrome延期.如果您没有使用该扩展程序,请尝试停用所有扩展程序,然后逐个重新启用它们?
小智 18
该错误通常是由Chrome扩展程序引起的。尝试禁用所有扩展,问题应该消失。
Dav*_*han 14
如果您是扩展程序开发人员,请查看此Chrome 扩展程序消息传递:Unchecked runtime.lastError:无法建立连接。接收端不存在
问题的核心是 chrome API 行为发生了变化,您需要为其添加解决方法。
kai*_*eal 12
解
对于Chrome:
您打开带有控制台错误的窗口,然后打开另一个新窗口。
在第二个窗口中,转到:chrome:// extensions
通过切换禁用每个扩展(每个卡的右下角的蓝色滑块),并在切换每个扩展后使用控制台刷新窗口。
一旦没有错误,请删除扩展名。
Nir*_*mar 11
您需要window.chrome.runtime.lastError
在runtime.sendMessage
回调中处理。这个错误只需要处理。下面是我的代码:
window.chrome.runtime.sendMessage(
EXTENSION_ID,
{ message:"---" }, // jsonable message
(result) => {
if (!window.chrome.runtime.lastError) {
// message processing code goes here
} else {
// error handling code goes here
}
}
);
});
Run Code Online (Sandbox Code Playgroud)
ash*_*deh 10
简单的回答:
如果您没有收到另一端的响应,它也会告诉您接收端不存在。
详细回答:
如果您没有从另一端得到答复,它也会告诉您接收端不存在。因此,如果您有任何应在 .sendMessage 部分中使用响应的回调函数,您应该删除它,或者如果您可能没有来自另一方的响应,则应处理它。
所以
如果我想重写google API 消息传递文档的简单一次性请求部分,我将在消息发送方法中使用回调函数的错误处理程序来编写它,如下所示:
从内容脚本发送请求如下所示:
chrome.runtime.sendMessage({greeting: "hello"}, function (response) {
if (!chrome.runtime.lastError) {
// if you have any response
} else {
// if you don't have any response it's ok but you should actually handle
// it and we are doing this when we are examining chrome.runtime.lastError
}
});
Run Code Online (Sandbox Code Playgroud)
从扩展程序向内容脚本发送请求看起来非常相似,只是您需要指定将其发送到哪个选项卡。此示例演示向所选选项卡中的内容脚本发送消息。
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
if (!chrome.runtime.lastError) {
// if you have any response
} else {
// if you don't have any response it's ok but you should actually handle
// it and we are doing this when we are examining chrome.runtime.lastError
}
});
});
Run Code Online (Sandbox Code Playgroud)
在接收端,您需要设置一个runtime.onMessage事件监听器来处理消息。从内容脚本或扩展页面来看,这看起来是一样的。
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting === "hello")
sendResponse({farewell: "goodbye"});
}
);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
36363 次 |
最近记录: |