Waqar Ahmed
Waqar Ahmed

Reputation: 1444

Send message to Chrome App from Web Page

app.js

chrome.runtime.onMessageExternal.addListener(
  function (request, sender, sendResponse) {
      console.log("Message Recived");        
  });

Page.html

chrome.runtime.sendMessage("From WebPage", { openUrlInEditor: "http://localhost:54854/MainPage.html" },
          function (response) {             

          });

manifest.json

"externally_connectable": {
  "matches": ["*://*.example.com/*"]
}

But still I cant send message from Web Page to Chrome APP. Reference: https://developer.chrome.com/extensions/messaging#external

Kindly Help me :(

Upvotes: 1

Views: 906

Answers (1)

Xan
Xan

Reputation: 77502

The first argument of chrome.runtime.sendMessage for sending an external message is not an arbitrary ID, but the ID of the extension/app that will receive the message.

For published apps, the ID is fixed at the moment you first submit it to the store.

For unpacked apps, the ID is determined by the "key" field in the manifest, if any, or by the path to the folder. It may be useful to fix the ID for development, so that it does not change from computer to computer.

Upvotes: 1

Related Questions