right now I'm developing a Chrome extension with Google's Dart. All works fine, except the onMessage-handling.
Chrome-Package used: API Ref. ~ OnMessageEvent Ref.
In the background-script i'm calling:
import 'package:chrome/chrome_ext.dart' as chrome;
void main() {
//...
//Binde event-listeners
chrome.runtime.onMessage.listen(onMessage);
//...
}
/**
* Message event handling
*/
bool onMessage(chrome.OnMessageEvent messageEvent){
JsObject message = messageEvent.message;
JsFunction response = messageEvent.sendResponse;
switch(message['action']){
//...
//Used by popup
case 'refresh':
print('Refresh called!');
chrome.storage.sync.get().then((_){
new JsObject(response, [new JsObject.jsify({'done': true})]);
});
//Idicate to send a response asynchronously (So it's said in the OnMessageEvent Ref.)
return true;
//...
}
return false;
}
My popup-scripts looks like this:
//...
chrome.runtime.sendMessage({
'action': "refresh"
}).then((_){
print('receiving response!');
});
//...
What is working:
The message 'refresh' send from popup-script to background-script works!
The background-script prints Refresh called!
What is not working:
The popup-script never receives the response called from the background-script: new JsObject(response, [new JsObject.jsify({'done': true})]);
.
I don't know how to handel sendResponse to really send an response. Maybe my call with JsObject is wrong? Hope someone else can help. (Btw. also a non async-response doesn't work here)
This problem is also open on github.com/dart-gde/chrome.dart.