admin管理员组文章数量:1417043
Chrome extension launches the app in a separate window from the domain "http://localhost:3000" . The domain uses the app React.
My React App:
React:
ponentDidMount() {
let connectApp = chrome.runtime.connect(
"ID My Chrome Extension",
{
name: "test",
}
);
connectApp.onMessage.addListener((msg, sender, sendResponse) => {
console.log(msg);
});
connectApp.onDisconnect.addListener((obj) => {
console.log("disconnected port", obj);
});
}
Chrome Extantion:
background.js
function sendInfoProspectWithDom(data) {
chrome.runtime.sendMessage({
text: "create-new-propsect"
});
}
chrome.runtime.onConnect.addListener(function (obj) {
console.log("onConnect");
});
manifest.json
{
"manifest_version": 2,
"name": "test",
"version": "1.1.0",
"description": "test Description",
"browser_action": {},
"background": {
"scripts": ["background.js"],
"persistent": true
},
"content_scripts": [
{
"matches": ["*://mail.google/*"],
"js": ["content.js"]
}
],
"externally_connectable": {
"ids": ["*"],
"matches": [
"https://localhost:3000/*",
"http://localhost:3000/*"
],
"accepts_tls_channel_id": false
},
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"permissions": [
"tabs",
"activeTab",
"https://*/*",
"http://*/*"
]
}
Error:
Chrome extension launches the app in a separate window from the domain "http://localhost:3000" . The domain uses the app React.
My React App:
React:
ponentDidMount() {
let connectApp = chrome.runtime.connect(
"ID My Chrome Extension",
{
name: "test",
}
);
connectApp.onMessage.addListener((msg, sender, sendResponse) => {
console.log(msg);
});
connectApp.onDisconnect.addListener((obj) => {
console.log("disconnected port", obj);
});
}
Chrome Extantion:
background.js
function sendInfoProspectWithDom(data) {
chrome.runtime.sendMessage({
text: "create-new-propsect"
});
}
chrome.runtime.onConnect.addListener(function (obj) {
console.log("onConnect");
});
manifest.json
{
"manifest_version": 2,
"name": "test",
"version": "1.1.0",
"description": "test Description",
"browser_action": {},
"background": {
"scripts": ["background.js"],
"persistent": true
},
"content_scripts": [
{
"matches": ["*://mail.google./*"],
"js": ["content.js"]
}
],
"externally_connectable": {
"ids": ["*"],
"matches": [
"https://localhost:3000/*",
"http://localhost:3000/*"
],
"accepts_tls_channel_id": false
},
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"permissions": [
"tabs",
"activeTab",
"https://*/*",
"http://*/*"
]
}
Error:
Share Improve this question edited Apr 25, 2020 at 13:34 Aleksey Ladutska Ladutia asked Apr 24, 2020 at 18:50 Aleksey Ladutska LadutiaAleksey Ladutska Ladutia 131 gold badge1 silver badge5 bronze badges1 Answer
Reset to default 2The error message means there is no correctly registered listener or the extension wasn't enabled at the time the message was sent.
See sending messages from web pages section:
From your app or extension, you may listen to messages from web pages via the runtime.onMessageExternal or runtime.onConnectExternal APIs, similar to cross-extension messaging. Only the web page can initiate a connection.
So you need to replace onConnect with onConnectExternal:
chrome.runtime.onConnectExternal.addListener(port => {
//
});
本文标签:
版权声明:本文标题:javascript - "Could not establish connection. Receiving end does not exist" error trying to connect from React 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745266077a2650608.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论