Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
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,7 @@
## 1.1.0

* Added `runJavaScript` and `runJavaScriptForResult` interface methods to supersede `evaluateJavaScript`.

## 1.0.0

* Extracted platform interface from `webview_flutter`.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ class MethodChannelWebViewPlatform implements WebViewPlatformController {
.then((result) => result!);
}

@override
Future<void> runJavaScript(String javaScriptString) async {
await _channel.invokeMethod<String>('runJavaScript', javaScriptString);
}

@override
Future<String> runJavaScriptForResult(String javaScriptString) {
Comment thread
BeMacized marked this conversation as resolved.
Outdated
return _channel
.invokeMethod<String>('runJavaScriptForResult', javaScriptString)
.then((result) => result!);
}

@override
Future<void> addJavascriptChannels(Set<String> javascriptChannelNames) {
return _channel.invokeMethod<void>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ abstract class WebViewPlatformController {
"WebView evaluateJavascript is not implemented on the current platform");
}

/// Runs the given JavaScript in the context of the current page.
///
/// The Future completes with an error if a JavaScript error occurred.
Future<void> runJavaScript(String javaScriptString) {
Comment thread
BeMacized marked this conversation as resolved.
Outdated
throw UnimplementedError(
"WebView runJavaScript is not implemented on the current platform");
}

/// Runs the given JavaScript in the context of the current page, and returns the result.
///
/// The Future completes with an error if a JavaScript error occurred, or if the type of the
/// evaluated expression is not supported(e.g on iOS not all non primitive type can be evaluated).
Comment thread
BeMacized marked this conversation as resolved.
Outdated
Comment thread
BeMacized marked this conversation as resolved.
Outdated
Future<String> runJavaScriptForResult(String javaScriptString) {
throw UnimplementedError(
"WebView runJavaScriptForResult is not implemented on the current platform");
}

/// Adds new JavaScript channels to the set of enabled channels.
///
/// For each value in this list the platform's webview should make sure that a corresponding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/master/packages/webview_flut
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: 1.0.0
version: 1.1.0

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void main() {
case 'canGoBack':
case 'canGoForward':
return true;
case 'runJavaScriptForResult':
case 'evaluateJavascript':
return methodCall.arguments as String;
case 'getScrollX':
Expand Down Expand Up @@ -280,6 +281,40 @@ void main() {
);
});

test('runJavaScript', () async {
await webViewPlatform.runJavaScript(
'This simulates some Javascript code.',
Comment thread
BeMacized marked this conversation as resolved.
Outdated
);

expect(
log,
<Matcher>[
isMethodCall(
'runJavaScript',
arguments: 'This simulates some Javascript code.',
),
],
);
});

test('runJavaScriptForResult', () async {
final String evaluateJavascript =
await webViewPlatform.runJavaScriptForResult(
'This simulates some Javascript code.',
);

expect('This simulates some Javascript code.', evaluateJavascript);
expect(
log,
<Matcher>[
isMethodCall(
'runJavaScriptForResult',
arguments: 'This simulates some Javascript code.',
),
],
);
});

test('addJavascriptChannels', () async {
final Set<String> channels = <String>{'channel one', 'channel two'};
await webViewPlatform.addJavascriptChannels(channels);
Expand Down