Reputation: 118
I cant connect with my extension.
I'm trying to connect, Im using repl.it to test but nothing.
My main.js
chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
console.log('Success!!');
console.log(request, sender, sendResponse);
}
);
My code in repl.it
chrome.runtime.sendMessage("hpibninopnnoohihjplmdcmjfkeepahh", {message: "Hello"}, function (response) {
console.log("Response: ", response);
})
My manifest.json
{
"manifest_version": 2,
"name": "Example",
"description": "Trying to connect",
"version": "0.1",
"externally_connectable": {
"matches": [
"https://repl.it/Ngjk"
]
},
"browser_action": {
"default_icon": "icon.png"
},
"background": {
"scripts": ["main.js"],
"persistent": true
},
"permissions": [
"activeTab",
"tabs",
"background"
]
}
I can't see the problem, other code works well but I cant connect and I dont know why.
Upvotes: 0
Views: 67
Reputation: 1755
You should modify your main.js.
chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
console.log('Success!!');
console.log(request, sender, sendResponse);
sendResponse({myResponse: 'hello'});
});
Moreover, you can add console.log(chrome.runtime.lastError );
inside your chrome.runtime.onMessageExternal.addListener to see errors if any.
EDIT
Your code will work if you open chrome dev tools on https://repl.it/Ngjk and run it in console. However, it doesn't work on https://repl.it/ because it is being executed from address about:blank.
Upvotes: 1