Dart SDK 2.9以下运行AngularDart应用 Chrome报错解决方案

Chrome浏览器运行AngularDart项目报错,控制台打印类似如下信息:

Unhandled error detected in the injected client.js script.

You can disable this script in webdev by passing --no-injected-client if it
is preventing your app from loading, but note that this will also prevent
all debugging and hot reload/restart functionality from working.

The original error is below, please file an issue at
https://github.com/dart-lang/webdev/issues/new and attach this output:

NoSuchMethodError: method not found: 'get$digestsPath' (J.getInterceptor$x(...).get$digestsPath is not a function)
TypeError: J.getInterceptor$x(...).get$digestsPath is not a function
    at Object.get$digestsPath$x (http://localhost:53322/dwds/src/injected/client.js:3507:43)
    at http://localhost:53322/dwds/src/injected/client.js:22732:60
    at _wrapJsFunctionForAsync_closure.$protected (http://localhost:53322/dwds/src/injected/client.js:3802:15)
    at _wrapJsFunctionForAsync_closure.call$2 (http://localhost:53322/dwds/src/injected/client.js:10996:12)
    at Object._asyncStartSync (http://localhost:53322/dwds/src/injected/client.js:3766:20)
    at RequireRestarter._getDigests$0 (http://localhost:53322/dwds/src/injected/client.js:22744:16)
    at http://localhost:53322/dwds/src/injected/client.js:22759:48
    at _wrapJsFunctionForAsync_closure.$protected (http://localhost:53322/dwds/src/injected/client.js:3802:15)
    at _wrapJsFunctionForAsync_closure.call$2 (http://localhost:53322/dwds/src/injected/client.js:10996:12)
    at Object._asyncStartSync (http://localhost:53322/dwds/src/injected/client.js:3766:20)
    at RequireRestarter._initialize$0 (http://localhost:53322/dwds/src/injected/client.js:22767:16)
    at http://localhost:53322/dwds/src/injected/client.js:8572:45
    at _wrapJsFunctionForAsync_closure.$protected (http://localhost:53322/dwds/src/injected/client.js:3802:15)
    at _wrapJsFunctionForAsync_closure.call$2 (http://localhost:53322/dwds/src/injected/client.js:10996:12)
    at Object._asyncStartSync (http://localhost:53322/dwds/src/injected/client.js:3766:20)
    at Object.RequireRestarter_create (http://localhost:53322/dwds/src/injected/client.js:8584:16)
    at http://localhost:53322/dwds/src/injected/client.js:22319:38
    at _wrapJsFunctionForAsync_closure.$protected (http://localhost:53322/dwds/src/injected/client.js:3802:15)
    at _wrapJsFunctionForAsync_closure.call$2 (http://localhost:53322/dwds/src/injected/client.js:10996:12)
    at _awaitOnObject_closure.call$1 (http://localhost:53322/dwds/src/injected/client.js:10982:32)
    at StaticClosure._rootRunUnary [as call$2$5](http://localhost:53322/dwds/src/injected/client.js:4130:18)
    at _CustomZone.runUnary$2$2 (http://localhost:53322/dwds/src/injected/client.js:12301:39)
    at _Future__propagateToListeners_handleValueCallback.call$0 (http://localhost:53322/dwds/src/injected/client.js:11362:51)
    at Object._Future__propagateToListeners (http://localhost:53322/dwds/src/injected/client.js:3914:93)
    at _Future._complete$1 (http://localhost:53322/dwds/src/injected/client.js:11186:11)
    at Object._cancelAndValue (http://localhost:53322/dwds/src/injected/client.js:4069:16)
    at Stream_first_closure0.call$1 (http://localhost:53322/dwds/src/injected/client.js:11454:9)
    at _EventStreamSubscription_onData_closure.call$1 (http://localhost:53322/dwds/src/injected/client.js:17309:30)
    at StaticClosure._rootRunUnary [as call$2$5](http://localhost:53322/dwds/src/injected/client.js:4136:16)
    at _CustomZone.runUnary$2$2 (http://localhost:53322/dwds/src/injected/client.js:12301:39)
    at _CustomZone.runUnaryGuarded$1$2 (http://localhost:53322/dwds/src/injected/client.js:12233:14)
    at _CustomZone_bindUnaryCallbackGuarded_closure.call$1 (http://localhost:53322/dwds/src/injected/client.js:12436:25)
    at invokeClosure (http://localhost:53322/dwds/src/injected/client.js:1204:26)
    at EventSource.<anonymous> (http://localhost:53322/dwds/src/injected/client.js:1223:18)

这是因为Chrome浏览器新版本API更改引起的,不再公开window.performance.memory的构造函数(而是使用Object的构造函数),hack评估结果为true(window.performance.memory 是 html.MemoryInfo)。
解决方法:
在AngularDart项目的web目录中的index.html文件中添加如下脚本:

<script>
    if (typeof window.MemoryInfo == "undefined") {
      if (typeof window.performance.memory != "undefined") {
        window.MemoryInfo = function () {};
        window.MemoryInfo.prototype = window.performance.memory.__proto__;
      }
    }
</script>
上一篇:《Total Commander:万能文件管理器》——第7.2节.比较和同步文件夹


下一篇:如何在OA系统中设定审批流程(一)固定流程