Google chrome extension 在dart中构建chrome扩展时chrome.runtime.onConnect出现问题

Google chrome extension 在dart中构建chrome扩展时chrome.runtime.onConnect出现问题,google-chrome-extension,dart,dart-js-interop,Google Chrome Extension,Dart,Dart Js Interop,运行chrome扩展的编译版本时,我遇到以下问题: Uncaught TypeError: undefined is not a function 执行时 context['chrome']['runtime']['onConnect'].callMethod('addListener',[(port){…}]); 我创建了一个可能指向原因的示例: 背景.省道 导入'dart:js'; void main(){ 打印(“main():context['chrome']['runtime'][

运行chrome扩展的编译版本时,我遇到以下问题:

Uncaught TypeError: undefined is not a function
执行时

context['chrome']['runtime']['onConnect'].callMethod('addListener',[(port){…}]);
我创建了一个可能指向原因的示例:

背景.省道
导入'dart:js';
void main(){
打印(“main():context['chrome']['runtime']['onConnect'](${context['chrome']['runtime']['onConnect'].runtimeType}):${context['chrome']['runtime']['onConnect']});
}
Dartium印刷品:

main():上下文['chrome']['runtime']['onConnect'](JsObject):[object]
但在Chrome中:

main():上下文['chrome']['runtime']['onConnect'](事件):事件的实例
它与()有关吗


在查看
chrome.dart
软件包中的
common.dart
后,是否有人可以建议如何注册在Dartium和chrome中都可用的
chrome.runtime.onConnect
侦听器

void _ensureHandlerAdded() {
  if (!_handlerAdded) {
    // TODO: Workaround an issue where the event objects are not properly
    // proxied in M35 and after.
    var jsEvent = _api[_eventName];
    JsObject event = (jsEvent is JsObject ? jsEvent : new JsObject.fromBrowserObject(jsEvent));
    event.callMethod('addListener', [_listener]);
    _handlerAdded = true;
  }
}
似乎有必要将
Event
包装到
JsObject
中,使其在
dart:js
中工作

同样的要求也适用于以下方面:

  • 端口断开连接
  • port.onMessage
如果有人知道跟踪此问题的现有问题,请随时添加