1

I built a React based Chrome extension, I want to do an AJAX call to my server from the extension. So I'm using chrome.runtime.sendMessage and chrome.runtime.onMessage.addListener.

I took the simplest example from Chrome Message Passing , but I'm getting the following error:

Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

I tried disabling all other Chrome extensions but that didn't help. I'm quite confident it has to do with webpack and scoping but I couldn't figure it out.

Sample code

Ohad Dahan
  • 371
  • 3
  • 14
  • Any way I could reproduce this? Looks like either your server is not reachable or some error in your messaging – Shubham Jain Aug 26 '19 at 19:04
  • It's **really** required to show the actual code in almost any extension-related question. So far I can only guess you do sendResponse inside a nested asynchronous callback and hence need "return true" at the end of the listener, [more info](https://developer.chrome.com/extensions/runtime#event-onMessage). Another common mistake is the wrong timing of sending/receiving but I need to see an [MCVE](/help/mcve) first. – wOxxOm Aug 26 '19 at 19:05
  • @wOxxOm here is a code sample: https://gist.github.com/ohaddahan/b46165763ab5fd10173c1f39432736b7 – Ohad Dahan Aug 26 '19 at 19:14
  • @OhadDahan add it to the question. – Marco Bonelli Aug 26 '19 at 23:28
  • If onMessage is inside a content script then you need to use a different sendMessage, [example](/a/14245504) – wOxxOm Aug 27 '19 at 04:11

0 Answers0