Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webview_flutter_platform_interface] Adds option to override console log #4701

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.5.0

* Adds support to register a callback to intercept messages that are written to
the JavaScript console. See `PlatformWebViewController.setConsoleLogCallback`.

## 2.4.0

* Adds support to retrieve the url from a web resource loading error. See `WebResourceError.url`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@ abstract class PlatformWebViewController extends PlatformInterface {
'setOnPermissionRequest is not implemented on the current platform',
);
}

/// Sets a callback that notifies the host application of any console messages
/// written to the JavaScript console.
Future<void> setOnConsoleMessage(
void Function(JavaScriptConsoleMessage consoleMessage) onConsoleMessage) {
throw UnimplementedError(
'setConsoleLogCallback is not implemented on the current platform',
);
}
}

/// Describes the parameters necessary for registering a JavaScript channel.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:meta/meta.dart';

import 'javascript_log_level.dart';

/// Represents a console message written to the JavaScript console.
@immutable
class JavaScriptConsoleMessage {
/// Creates a [JavaScriptConsoleMessage].
const JavaScriptConsoleMessage({
required this.level,
required this.message,
});

/// The severity of a JavaScript log message.
final JavaScriptLogLevel level;

/// The message written to the console.
final String message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// Represents the severity of a JavaScript log message.
enum JavaScriptLogLevel {
/// Indicates an error message was logged via an "error" event of the
/// `console.error` method.
error,

/// Indicates a warning message was logged using the `console.warning`
/// method.
warning,

/// Indicates a debug message was logged using the `console.debug` method.
debug,

/// Indicates an informational message was logged using the `console.info`
/// method.
info,

/// Indicates a log message was logged using the `console.log` method.
log,
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// found in the LICENSE file.

export 'http_response_error.dart';
export 'javascript_console_message.dart';
export 'javascript_log_level.dart';
export 'javascript_message.dart';
export 'javascript_mode.dart';
export 'load_request_params.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/webview_flutt
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview_flutter%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.4.0
version: 2.5.0

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,20 @@ void main() {
throwsUnimplementedError,
);
});

test(
'Default implementation of setConsoleLogCallback should throw unimplemented error',
() {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
const PlatformWebViewControllerCreationParams());

expect(
() =>
controller.setOnConsoleMessage((JavaScriptConsoleMessage message) {}),
throwsUnimplementedError,
);
});
}

class MockWebViewPlatformWithMixin extends MockWebViewPlatform
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Mocks generated by Mockito 5.4.0 from annotations
// Mocks generated by Mockito 5.4.1 from annotations
// in webview_flutter_platform_interface/test/platform_webview_controller_test.dart.
// Do not manually edit this file.

// @dart=2.19

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i4;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Mocks generated by Mockito 5.4.0 from annotations
// Mocks generated by Mockito 5.4.1 from annotations
// in webview_flutter_platform_interface/test/webview_platform_test.dart.
// Do not manually edit this file.

// @dart=2.19

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:mockito/mockito.dart' as _i1;
import 'package:webview_flutter_platform_interface/src/platform_navigation_delegate.dart'
Expand Down