I have a simple content script that is trying to ask the background script for some data. However it seems if the response takes any time at all the callback won't be triggered. Is this just how chrome extensions work? I suppose I could send a message back to the tab manually
This works
# CONTENT_SCRIPT
chrome.runtime.sendMessage { greeting: 'hello' }, (response) ->
console.log 'RECEIVED MESSAGE FROM BACKROUND'
console.log JSON.stringify(response.action, null, 3)
#successfully outputs panda here
return
# BACKROUND_SCRIPT
chrome.runtime.onMessage.addListener (request, sender, sendResponse) ->
console.log 'RECEIVED MESSAGE FROM CONTENT'
sendResponse {action: 'panda'}
This does not work
# CONTENT_SCRIPT
chrome.runtime.sendMessage { greeting: 'hello' }, (response) ->
# this code is never triggered
console.log 'RECEIVED MESSAGE FROM BACKROUND'
console.log JSON.stringify(response.action, null, 3)
return
# BACKROUND_SCRIPT
chrome.runtime.onMessage.addListener (request, sender, sendResponse) ->
console.log 'RECEIVED MESSAGE FROM CONTENT'
setTimeout (->
# I see the response in my logs
console.log 'response'
sendResponse {action: 'panda'}
), 3000