0

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.

Alvaro Molina
  • 108
  • 1
  • 12
  • main.js doesn't send any response so it's not clear what the problem is. Set a breakpoint in [devtools for the background page](https://stackoverflow.com/a/10258029) and see what happens. – wOxxOm Nov 03 '17 at 09:49
  • I put a breapoint in the console.log("Sucess!"), but nothing. I put some other code in the file to check if the file was loading ok and the code works. – Alvaro Molina Nov 03 '17 at 10:18

1 Answers1

1

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.

Iurii Drozdov
  • 1,685
  • 1
  • 12
  • 23