From af4e33222a84a0395cd8e26ae4f2b501f7248154 Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Thu, 18 Nov 2021 11:14:45 -0800 Subject: [PATCH 1/2] Use window.navigator.vendor to detect chromium-based browsers Previously we used `window.navigator.userAgent` to detect if the browser is chromium-based, but that detection fails during iphone simulation in chrome or egde. Change the detection to use `window.navigator.vendor` instead. CLoses: https://github.com/flutter/flutter/issues/92567 --- dwds/lib/src/injected/client.js | 39 ++++++++++++++++++++++++--------- dwds/web/client.dart | 2 +- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/dwds/lib/src/injected/client.js b/dwds/lib/src/injected/client.js index f493d1440..f0b162bb4 100644 --- a/dwds/lib/src/injected/client.js +++ b/dwds/lib/src/injected/client.js @@ -1,4 +1,4 @@ -// Generated by dart2js (NullSafetyMode.unsound, no-legacy-javascript, new-holders, csp), the Dart to JavaScript compiler version: 2.15.0-257.0.dev. +// Generated by dart2js (NullSafetyMode.unsound, no-legacy-javascript, new-holders, csp), the Dart to JavaScript compiler version: 2.16.0-21.0.dev. // The code supports the following hooks: // dartPrint(message): // if this function is defined it is called instead of the Dart [print] @@ -147,10 +147,11 @@ A.throwLateFieldADI(name); holder[name] = value; } + var finalValue = holder[name]; holder[getterName] = function() { - return this[name]; + return finalValue; }; - return holder[name]; + return finalValue; }; } function makeConstList(list) { @@ -762,10 +763,16 @@ return result; }, Primitives_objectHashCode(object) { - var hash = object.$identityHash; + var hash, + property = $.Primitives__identityHashCodeProperty; + if (property == null) { + property = Symbol("identityHashCode"); + $.Primitives__identityHashCodeProperty = property; + } + hash = object[property]; if (hash == null) { hash = Math.random() * 0x3fffffff | 0; - object.$identityHash = hash; + object[property] = hash; } return hash; }, @@ -4929,6 +4936,12 @@ return object.toString$0(0); return "Instance of '" + A.S(A.Primitives_objectTypeName(object)) + "'"; }, + Error__throw(error, stackTrace) { + error = A.wrapException(error); + error.stack = J.toString$0$(stackTrace); + throw error; + throw A.wrapException("unreachable"); + }, DateTime$fromMillisecondsSinceEpoch(millisecondsSinceEpoch, isUtc) { var t1; if (Math.abs(millisecondsSinceEpoch) <= 864e13) @@ -5468,6 +5481,12 @@ return JSON.stringify(object); return A.Error__objectToString(object); }, + Error_throwWithStackTrace(error, stackTrace) { + A.checkNotNullable(error, "error", type$.Object); + A.checkNotNullable(stackTrace, "stackTrace", type$.StackTrace); + A.Error__throw(error, stackTrace); + A.ReachabilityError$(string$._null_); + }, AssertionError$(message) { return new A.AssertionError(message); }, @@ -13010,9 +13029,8 @@ }; A._rootHandleError_closure.prototype = { call$0() { - var error = A.wrapException(this.error); - error.stack = J.toString$0$(this.stackTrace); - throw error; + A.Error_throwWithStackTrace(this.error, this.stackTrace); + A.ReachabilityError$(string$._null_); }, $signature: 0 }; @@ -23711,7 +23729,7 @@ type$.nullable_void_Function._as(null); A._EventStreamSubscription$(t1, "keydown", t2, false, type$.legacy_KeyboardEvent); } - if (J.contains$1$asx(window.navigator.userAgent, "Chrome")) { + if (J.contains$1$asx(window.navigator.vendor, "Google")) { t1 = client.get$sink(); t2 = $.$get$serializers(); t3 = new A.ConnectRequestBuilder(); @@ -23781,7 +23799,7 @@ A.main__closure2.prototype = { call$0() { var t1, t2, t3; - if (!J.contains$1$asx(window.navigator.userAgent, "Chrome")) { + if (!J.contains$1$asx(window.navigator.vendor, "Google")) { B.Window_methods.alert$1(window, "Dart DevTools is only supported on Chromium based browsers."); return; } @@ -25305,6 +25323,7 @@ (function staticFields() { $._JS_INTEROP_INTERCEPTOR_TAG = null; $.printToZone = null; + $.Primitives__identityHashCodeProperty = null; $.BoundClosure__receiverFieldNameCache = null; $.BoundClosure__interceptorFieldNameCache = null; $.getTagFunction = null; diff --git a/dwds/web/client.dart b/dwds/web/client.dart index 1ddb84d11..3e3b41a72 100644 --- a/dwds/web/client.dart +++ b/dwds/web/client.dart @@ -223,4 +223,4 @@ external set emitDebugEvent(void Function(String, String) func); @JS(r'$emitRegisterEvent') external set emitRegisterEvent(void Function(String) func); -bool get _isChromium => window.navigator.userAgent.contains('Chrome'); +bool get _isChromium => window.navigator.vendor.contains('Google'); From 8416c1e670bbd38531b2328d9de9ab2489079f93 Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Thu, 18 Nov 2021 11:21:41 -0800 Subject: [PATCH 2/2] Update changelog --- dwds/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 391ed4c2a..17ec6b9c8 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -11,6 +11,8 @@ used by DDR, and is not yet supported for amd modules that are used by flutter tools and webdev. +- Fix chrome detection in iPhone emulation mode in chrome or edge browsers. + ## 11.4.0 - Fix duplicated scripts returned by `VmService.getScripts` API.