To better describe my problem i have created a small example of a chrome extension written in Dart.
You can see the code or download the extension on Gist.
Uncaught TypeError: undefined is not a function for the line:
How far i already am
- As you may see in the example the functions
dart:jsare also working in the js-extension. So it could be a special problem with dart2js and adding eventlisteners?
- Also printing out
context['chrome']['runtime']['onMessage']shows the right event-object. (E.g.:
- I know that there exist an chrome pub package, but there is still a bug when responding to received messages in onMessage. See also this question. Using the chrome api directly via dart:js was the workaround which was fine at that dart version.
I played a lot with the code but all results in the same error. Now i am out of ideas. Hope the community can help me again.
I have now reported this bug on dartbug.com as Robert suggested.
Anyway, I’m still open for a workaround or something if someone know one.
As keerti already mentioned: A similar problem with a workaround can be find here.
My solution looks like this:
//Tmp: sendResponse is buged, so we use the js-version //chrome.runtime.onMessage.listen(onMessageDartListener); //..and ofcourse the js-version is buged too. So this workaround here: var jsOnMessageEvent = context['chrome']['runtime']['onMessage']; JsObject dartOnMessageEvent = (jsOnMessageEvent is JsObject ? jsOnMessageEvent : new JsObject.fromBrowserObject(jsOnMessageEvent)); dartOnMessageEvent.callMethod('addListener', [onMessageListener]);
Answered By – Andi
Answer Checked By – Candace Johnson (FlutterFixes Volunteer)