Skip to content

Commit 12fad6d

Browse files
[webview_flutter_wkwebview] Replace Flutter method failure assertion with nslog (#9587)
The assertion caused a crash with hot restart if a Flutter method call happened at the same time. Changing this to `NSLog` also allows logging failures when in release mode. Fixes flutter/flutter#170643 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 2a0b7ef commit 12fad6d

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## NEXT
1+
## 3.22.1
22

3+
* Changes the handling of a Flutter method failure from throwing an assertion error to logging the
4+
error.
35
* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.
46

57
## 3.22.0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import XCTest
6+
7+
@testable import webview_flutter_wkwebview
8+
9+
class ProxyAPIRegistrarTests: XCTestCase {
10+
func testLogFlutterMethodFailureDoesNotThrowAnError() {
11+
let registrar = TestProxyApiRegistrar()
12+
13+
XCTExpectFailure("Method should log a message and not throw an error.") {
14+
XCTAssertThrowsError(
15+
registrar.logFlutterMethodFailure(
16+
PigeonError(code: "code", message: "message", details: nil), methodName: "aMethod"))
17+
}
18+
}
19+
}

packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/ProxyAPIRegistrar.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ open class ProxyAPIRegistrar: WebKitLibraryPigeonProxyApiRegistrar {
6868
details: nil)
6969
}
7070

71-
// Creates an assertion failure when a Flutter method receives an error from Dart.
72-
fileprivate func assertFlutterMethodFailure(_ error: PigeonError, methodName: String) {
73-
assertionFailure(
71+
// Log when a Flutter method receives an error from Dart.
72+
func logFlutterMethodFailure(_ error: PigeonError, methodName: String) {
73+
NSLog(
7474
"\(String(describing: error)): Error returned from calling \(methodName): \(String(describing: error.message))"
7575
)
76+
NSLog("%@", Thread.callStackSymbols.joined(separator: "\n"))
7677
}
7778

7879
/// Handles calling a Flutter method on the main thread.
@@ -83,7 +84,7 @@ open class ProxyAPIRegistrar: WebKitLibraryPigeonProxyApiRegistrar {
8384
) {
8485
DispatchQueue.main.async {
8586
work { methodName, error in
86-
self.assertFlutterMethodFailure(error, methodName: methodName)
87+
self.logFlutterMethodFailure(error, methodName: methodName)
8788
}
8889
}
8990
}

packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
1111
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
1212
78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; };
13+
8F0EDFD32E1F4967001938E6 /* ProxyAPIRegistrarTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F0EDFD22E1F4967001938E6 /* ProxyAPIRegistrarTests.swift */; };
1314
8F1488E22D2DE27000191744 /* ScriptMessageHandlerProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1488D02D2DE27000191744 /* ScriptMessageHandlerProxyAPITests.swift */; };
1415
8F1488E32D2DE27000191744 /* TestProxyApiRegistrar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1488D62D2DE27000191744 /* TestProxyApiRegistrar.swift */; };
1516
8F1488E42D2DE27000191744 /* URLRequestProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1488DC2D2DE27000191744 /* URLRequestProxyAPITests.swift */; };
@@ -98,6 +99,7 @@
9899
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
99100
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
100101
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
102+
8F0EDFD22E1F4967001938E6 /* ProxyAPIRegistrarTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ProxyAPIRegistrarTests.swift; path = ../../darwin/Tests/ProxyAPIRegistrarTests.swift; sourceTree = SOURCE_ROOT; };
101103
8F1488C52D2DE27000191744 /* ErrorProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ErrorProxyAPITests.swift; path = ../../darwin/Tests/ErrorProxyAPITests.swift; sourceTree = SOURCE_ROOT; };
102104
8F1488C62D2DE27000191744 /* FrameInfoProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FrameInfoProxyAPITests.swift; path = ../../darwin/Tests/FrameInfoProxyAPITests.swift; sourceTree = SOURCE_ROOT; };
103105
8F1488C72D2DE27000191744 /* FWFWebViewFlutterWKWebViewExternalAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FWFWebViewFlutterWKWebViewExternalAPITests.swift; path = ../../darwin/Tests/FWFWebViewFlutterWKWebViewExternalAPITests.swift; sourceTree = SOURCE_ROOT; };
@@ -178,6 +180,7 @@
178180
68BDCAEA23C3F7CB00D9C032 /* RunnerTests */ = {
179181
isa = PBXGroup;
180182
children = (
183+
8F0EDFD22E1F4967001938E6 /* ProxyAPIRegistrarTests.swift */,
181184
8FEC64812DA2C6DC00C48569 /* GetTrustResultResponseProxyAPITests.swift */,
182185
8FEC64822DA2C6DC00C48569 /* SecCertificateProxyAPITests.swift */,
183186
8FEC64832DA2C6DC00C48569 /* SecTrustProxyAPITests.swift */,
@@ -561,6 +564,7 @@
561564
8F1488E82D2DE27000191744 /* ScriptMessageProxyAPITests.swift in Sources */,
562565
8F1488E92D2DE27000191744 /* UIViewProxyAPITests.swift in Sources */,
563566
8F1488EA2D2DE27000191744 /* SecurityOriginProxyAPITests.swift in Sources */,
567+
8F0EDFD32E1F4967001938E6 /* ProxyAPIRegistrarTests.swift in Sources */,
564568
8F1488EB2D2DE27000191744 /* PreferencesProxyAPITests.swift in Sources */,
565569
8F1488EC2D2DE27000191744 /* FrameInfoProxyAPITests.swift in Sources */,
566570
8F1488ED2D2DE27000191744 /* ErrorProxyAPITests.swift in Sources */,

packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: webview_flutter_wkwebview
22
description: A Flutter plugin that provides a WebView widget based on Apple's WKWebView control.
33
repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_wkwebview
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22
5-
version: 3.22.0
5+
version: 3.22.1
66

77
environment:
88
sdk: ^3.6.0

0 commit comments

Comments
 (0)