chrom extension external connected

98 views
Skip to first unread message

woodlu...@gmail.com

unread,
Jun 23, 2017, 4:37:10 AM6/23/17
to Chromium-Extensions-Announce
I want to call function in my chrome extension from my web site but i dosn't work.

My web site:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<script>

function skan()
{
   var editorExtensionId = "mfiphnfecnfhmhbfnnoicdnbcdacakpf";

            // Make a simple request:
        
            chrome.runtime.sendMessage(editorExtensionId, {Open: 'tekst'},
              function(response) {
                 // if (!response.success)
                   alert(response)
              });
}
</script>
<body>
 <button onclick="skan()">Skan</button>

</body>

</html>

My extension code:

background.js


chrome.runtime.onMessageExternal.addListener(
  function(request, sender, sendResponse) {
    // don't allow this web page access
    if (request.Open)
      alert(request.Open);
  });

manifest.json

{
  "name": "test",
  "description": "test",
  "version": "0.7",
  "permissions": [
    "debugger"
  ],
  "background": {
    "scripts": ["background.js"]
  },
  "browser_action": {
    "default_icon": "icon.png",
    "default_title": "test"
  },
  "manifest_version": 2
}

When i call from webpage response is undefined. Event isn't call in chrome extension .Id extension is correct.

Where is problem. Thanks
 


PhistucK

unread,
Jun 23, 2017, 5:38:06 AM6/23/17
to woodlu...@gmail.com, Chromium-Extensions-Announce
1. I believe response will be undefined if you do not call sendResponse on the other end.
2. You have to make your extension externally connectable by adding a manifest key. See https://developer.chrome.com/extensions/manifest/externally_connectable for details.


PhistucK

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-extensions@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/b24b3e09-5d23-4614-be3c-9c49e5859307%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

woodlu...@gmail.com

unread,
Jun 23, 2017, 6:46:09 AM6/23/17
to Chromium-Extensions-Announce, woodlu...@gmail.com
I have add externally_connectable like below:

"externally_connectable": {
  
    "ids": [
      "*"
    ],
     "accepts_tls_channel_id": false,
     "matches": [
      "file:///D:/pak4/test.html"
    
    ]
}

Result is the same.

woodlu...@gmail.com

unread,
Jun 23, 2017, 8:00:38 AM6/23/17
to Chromium-Extensions-Announce, woodlu...@gmail.com
Its work . I have to change 'mathes'

woodlu...@gmail.com

unread,
Jun 23, 2017, 8:01:01 AM6/23/17
to Chromium-Extensions-Announce, woodlu...@gmail.com
Thanks
Reply all
Reply to author
Forward
0 new messages