0

How can we implement this in dart 2?

content_script.js:

chrome.runtime.sendMessage("hello", function(response) { console.log(response); });

backgroud.js:

chrome.runtime.onMessage.addListener(function(a,b, responseCallback){ responseCallback("world"); });

When responseCallback("world"); is called from dart it doesn't send the response back to sender.

I already have implemented an example that is able to read parameters from events when they are fired but it is not able to send a response because responseCallback is passed as a parameter : https://gitlab.com/drbcode/chrome.dart/blob/master/examples/runtime_test/lib/runtime.dart#L46

API docs:

https://developer.chrome.com/apps/runtime#method-sendMessage https://developer.chrome.com/apps/runtime#event-onMessage

1 Answers1

0

After stumbling for a while I found this about chrome.runtime.onMessage on stackoverflow:

Chrome Extension Message passing: response not sent

chrome.runtime.onMessage.addListener:

This function becomes invalid when the event listener returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open to the other end until sendResponse is called).

Those who are curious about implementing an event listener("similar to above") using dart js interop can check out this repo:

https://github.com/drbcode/dart_event_listener_example