From 7bb70eb7d97ef36866af5915c61548a456a45578 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Wed, 6 Dec 2023 02:19:40 +0100 Subject: [PATCH] fix #1900, Try to load just the URL of an URLRequest if the HTTP method is GET and the HTTP request fails due to an error such as a CORS policy error #1901 --- .github/ISSUE_TEMPLATE/BUG_REPORT.md | 17 ++-- .../pubspec.yaml | 2 +- dev_packages/generators/pubspec.yaml | 8 +- flutter_inappwebview/pubspec.yaml | 2 +- .../example/pubspec.yaml | 3 +- flutter_inappwebview_ios/example/pubspec.yaml | 3 +- .../example/pubspec.yaml | 3 +- flutter_inappwebview_web/CHANGELOG.md | 5 ++ flutter_inappwebview_web/example/pubspec.lock | 90 +++++++++++-------- flutter_inappwebview_web/example/pubspec.yaml | 3 +- .../lib/web/in_app_web_view_web_element.dart | 17 +++- .../lib/web/shims/platform_view_registry.dart | 2 + .../shims/platform_view_registry_dart_ui.dart | 10 +++ .../platform_view_registry_dart_ui_web.dart | 11 +++ .../lib/web/web_platform.dart | 3 +- flutter_inappwebview_web/pubspec.yaml | 2 +- 16 files changed, 121 insertions(+), 60 deletions(-) create mode 100644 flutter_inappwebview_web/lib/web/shims/platform_view_registry.dart create mode 100644 flutter_inappwebview_web/lib/web/shims/platform_view_registry_dart_ui.dart create mode 100644 flutter_inappwebview_web/lib/web/shims/platform_view_registry_dart_ui_web.dart diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.md b/.github/ISSUE_TEMPLATE/BUG_REPORT.md index ea8ae160..62863a34 100755 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.md +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.md @@ -23,14 +23,15 @@ labels: bug ## Environment -| Technology | Version | -|-----------------| ------------- | -| Flutter version | | -| Plugin version | | -| Android version | | -| iOS version | | -| macOS version | | -| Xcode version | | +| Technology | Version | +|-----------------------| ------------- | +| Flutter version | | +| Plugin version | | +| Android version | | +| iOS version | | +| macOS version | | +| Xcode version | | +| Google Chrome version | | Device information: diff --git a/dev_packages/flutter_inappwebview_internal_annotations/pubspec.yaml b/dev_packages/flutter_inappwebview_internal_annotations/pubspec.yaml index 210ffc15..215aca26 100755 --- a/dev_packages/flutter_inappwebview_internal_annotations/pubspec.yaml +++ b/dev_packages/flutter_inappwebview_internal_annotations/pubspec.yaml @@ -4,7 +4,7 @@ version: 1.1.1 homepage: https://github.com/pichillilorenzo/flutter_inappwebview environment: - sdk: ">=2.15.0 <4.0.0" + sdk: ">=2.17.0 <4.0.0" dev_dependencies: test: ^1.21.6 \ No newline at end of file diff --git a/dev_packages/generators/pubspec.yaml b/dev_packages/generators/pubspec.yaml index e0b29985..c470af0a 100755 --- a/dev_packages/generators/pubspec.yaml +++ b/dev_packages/generators/pubspec.yaml @@ -4,17 +4,17 @@ version: 1.0.0 publish_to: none environment: - sdk: ">=2.14.0 <3.0.0" - flutter: ">=2.5.0" + sdk: ">=2.17.0 <4.0.0" + flutter: ">=3.0.0" dependencies: flutter: sdk: flutter - build: ^2.4.0 + build: 2.3.1 source_gen: ^1.3.1 flutter_inappwebview_internal_annotations: ^1.1.1 dev_dependencies: - build_runner: ^2.4.2 + build_runner: 2.3.3 build_test: ^2.1.7 test: ^1.24.2 \ No newline at end of file diff --git a/flutter_inappwebview/pubspec.yaml b/flutter_inappwebview/pubspec.yaml index 41fb4721..c91de9d1 100755 --- a/flutter_inappwebview/pubspec.yaml +++ b/flutter_inappwebview/pubspec.yaml @@ -30,7 +30,7 @@ dev_dependencies: flutter_driver: sdk: flutter flutter_lints: ^2.0.1 - build_runner: ^2.2.1 + build_runner: 2.3.3 generators: path: ../dev_packages/generators diff --git a/flutter_inappwebview_android/example/pubspec.yaml b/flutter_inappwebview_android/example/pubspec.yaml index 4aaafc26..96949141 100644 --- a/flutter_inappwebview_android/example/pubspec.yaml +++ b/flutter_inappwebview_android/example/pubspec.yaml @@ -5,7 +5,8 @@ description: Demonstrates how to use the flutter_inappwebview_android plugin. publish_to: 'none' # Remove this line if you wish to publish to pub.dev environment: - sdk: '>=3.1.4 <4.0.0' + sdk: ">=2.17.0 <4.0.0" + flutter: ">=3.0.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions diff --git a/flutter_inappwebview_ios/example/pubspec.yaml b/flutter_inappwebview_ios/example/pubspec.yaml index 3eef0f0a..abb85f8f 100644 --- a/flutter_inappwebview_ios/example/pubspec.yaml +++ b/flutter_inappwebview_ios/example/pubspec.yaml @@ -5,7 +5,8 @@ description: Demonstrates how to use the flutter_inappwebview_ios plugin. publish_to: 'none' # Remove this line if you wish to publish to pub.dev environment: - sdk: '>=3.1.4 <4.0.0' + sdk: ">=2.17.0 <4.0.0" + flutter: ">=3.0.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions diff --git a/flutter_inappwebview_macos/example/pubspec.yaml b/flutter_inappwebview_macos/example/pubspec.yaml index 95aef948..a0a7e2df 100644 --- a/flutter_inappwebview_macos/example/pubspec.yaml +++ b/flutter_inappwebview_macos/example/pubspec.yaml @@ -5,7 +5,8 @@ description: Demonstrates how to use the flutter_inappwebview_macos plugin. publish_to: 'none' # Remove this line if you wish to publish to pub.dev environment: - sdk: '>=3.1.4 <4.0.0' + sdk: ">=2.17.0 <4.0.0" + flutter: ">=3.0.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions diff --git a/flutter_inappwebview_web/CHANGELOG.md b/flutter_inappwebview_web/CHANGELOG.md index 32cdbe53..26105cdc 100644 --- a/flutter_inappwebview_web/CHANGELOG.md +++ b/flutter_inappwebview_web/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.0.3 + +- Fixed "Flutter 3.7.10 error Dart library 'dart:ui_web' is not available on this platform" [#1900](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1900) +- Try to load just the URL of an URLRequest if the HTTP method is GET and the HTTP request fails due to an error, such as a CORS policy error + ## 1.0.2 - Updated `flutter_inappwebview_platform_interface` version dependency to `1.0.5` diff --git a/flutter_inappwebview_web/example/pubspec.lock b/flutter_inappwebview_web/example/pubspec.lock index f8e2cf56..fa069cc2 100644 --- a/flutter_inappwebview_web/example/pubspec.lock +++ b/flutter_inappwebview_web/example/pubspec.lock @@ -1,14 +1,22 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + sha256: "80e5141fafcb3361653ce308776cfd7d45e6e9fbb429e14eec571382c0c5fecb" + url: "https://pub.dev" + source: hosted + version: "3.3.2" async: dependency: transitive description: name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 url: "https://pub.dev" source: hosted - version: "2.11.0" + version: "2.10.0" boolean_selector: dependency: transitive description: @@ -21,10 +29,10 @@ packages: dependency: transitive description: name: characters - sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.2.1" clock: dependency: transitive description: @@ -37,10 +45,18 @@ packages: dependency: transitive description: name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 url: "https://pub.dev" source: hosted - version: "1.17.2" + version: "1.17.0" + crypto: + dependency: transitive + description: + name: crypto + sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 + url: "https://pub.dev" + source: hosted + version: "3.0.2" cupertino_icons: dependency: "direct main" description: @@ -130,50 +146,50 @@ packages: dependency: transitive description: name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" url: "https://pub.dev" source: hosted - version: "0.6.7" + version: "0.6.5" lints: dependency: transitive description: name: lints - sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" + sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593" url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.0.1" matcher: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.13" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.2.0" meta: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.8.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.8.2" platform: dependency: transitive description: @@ -186,10 +202,10 @@ packages: dependency: transitive description: name: plugin_platform_interface - sha256: f4f88d4a900933e7267e2b353594774fc0d07fb072b47eedcd5b54e1ea3269f8 + sha256: da3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d url: "https://pub.dev" source: hosted - version: "2.1.7" + version: "2.1.6" process: dependency: transitive description: @@ -207,10 +223,10 @@ packages: dependency: transitive description: name: source_span - sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.9.1" stack_trace: dependency: transitive description: @@ -255,10 +271,18 @@ packages: dependency: transitive description: name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.4.16" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5" + url: "https://pub.dev" + source: hosted + version: "1.3.1" vector_math: dependency: transitive description: @@ -271,26 +295,18 @@ packages: dependency: transitive description: name: vm_service - sha256: c620a6f783fa22436da68e42db7ebbf18b8c44b9a46ab911f666ff09ffd9153f + sha256: e7fb6c2282f7631712b69c19d1bff82f3767eea33a2321c14fa59ad67ea391c7 url: "https://pub.dev" source: hosted - version: "11.7.1" - web: - dependency: transitive - description: - name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 - url: "https://pub.dev" - source: hosted - version: "0.1.4-beta" + version: "9.4.0" webdriver: dependency: transitive description: name: webdriver - sha256: "3c923e918918feeb90c4c9fdf1fe39220fa4c0e8e2c0fffaded174498ef86c49" + sha256: ef67178f0cc7e32c1494645b11639dd1335f1d18814aa8435113a92e9ef9d841 url: "https://pub.dev" source: hosted - version: "3.0.2" + version: "3.0.1" sdks: - dart: ">=3.1.4 <4.0.0" + dart: ">=2.19.0 <3.0.0" flutter: ">=3.0.0" diff --git a/flutter_inappwebview_web/example/pubspec.yaml b/flutter_inappwebview_web/example/pubspec.yaml index 177696d3..bd06e077 100644 --- a/flutter_inappwebview_web/example/pubspec.yaml +++ b/flutter_inappwebview_web/example/pubspec.yaml @@ -5,7 +5,8 @@ description: Demonstrates how to use the flutter_inappwebview_web plugin. publish_to: 'none' # Remove this line if you wish to publish to pub.dev environment: - sdk: '>=3.1.4 <4.0.0' + sdk: ">=2.17.0 <4.0.0" + flutter: ">=3.0.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions diff --git a/flutter_inappwebview_web/lib/web/in_app_web_view_web_element.dart b/flutter_inappwebview_web/lib/web/in_app_web_view_web_element.dart index f5fe56a6..22fd79f8 100644 --- a/flutter_inappwebview_web/lib/web/in_app_web_view_web_element.dart +++ b/flutter_inappwebview_web/lib/web/in_app_web_view_web_element.dart @@ -5,6 +5,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; import 'dart:html'; import 'dart:js' as js; +import 'dart:developer'; import 'headless_inappwebview_manager.dart'; import 'web_platform_manager.dart'; @@ -51,8 +52,8 @@ class InAppWebViewWebElement implements Disposable { try { return await handleMethodCall(call); } on Error catch (e) { - print(e); - print(e.stackTrace); + log(e.toString(), + name: runtimeType.toString(), error: e, stackTrace: e.stackTrace); } }); @@ -291,7 +292,17 @@ class InAppWebViewWebElement implements Disposable { (urlRequest.headers == null || urlRequest.headers!.isEmpty)) { iframe.src = urlRequest.url.toString(); } else { - iframe.src = _convertHttpResponseToData(await _makeRequest(urlRequest)); + try { + iframe.src = _convertHttpResponseToData(await _makeRequest(urlRequest)); + } catch (e) { + log('Can\'t load the URLRequest for "${urlRequest.url}". Probably caused by a CORS policy error.', + name: runtimeType.toString(), error: e); + if (urlRequest.method == null || urlRequest.method == "GET") { + log('Load the request using just the URL.', + name: runtimeType.toString(), error: e); + iframe.src = urlRequest.url.toString(); + } + } } } diff --git a/flutter_inappwebview_web/lib/web/shims/platform_view_registry.dart b/flutter_inappwebview_web/lib/web/shims/platform_view_registry.dart new file mode 100644 index 00000000..900a2e0b --- /dev/null +++ b/flutter_inappwebview_web/lib/web/shims/platform_view_registry.dart @@ -0,0 +1,2 @@ +export 'platform_view_registry_dart_ui.dart' + if (dart.library.ui_web) 'platform_view_registry_dart_ui_web.dart'; diff --git a/flutter_inappwebview_web/lib/web/shims/platform_view_registry_dart_ui.dart b/flutter_inappwebview_web/lib/web/shims/platform_view_registry_dart_ui.dart new file mode 100644 index 00000000..1aaddc01 --- /dev/null +++ b/flutter_inappwebview_web/lib/web/shims/platform_view_registry_dart_ui.dart @@ -0,0 +1,10 @@ +import 'dart:html' as html; +import 'dart:ui' as ui; + +class platformViewRegistry { + static bool registerViewFactory( + String viewTypeId, html.Element Function(int viewId) viewFactory) { + // ignore: undefined_prefixed_name + return ui.platformViewRegistry.registerViewFactory(viewTypeId, viewFactory); + } +} diff --git a/flutter_inappwebview_web/lib/web/shims/platform_view_registry_dart_ui_web.dart b/flutter_inappwebview_web/lib/web/shims/platform_view_registry_dart_ui_web.dart new file mode 100644 index 00000000..5d069c3d --- /dev/null +++ b/flutter_inappwebview_web/lib/web/shims/platform_view_registry_dart_ui_web.dart @@ -0,0 +1,11 @@ +import 'dart:html' as html; +// ignore: uri_does_not_exist +import 'dart:ui_web' as ui_web; + +class platformViewRegistry { + static bool registerViewFactory( + String viewTypeId, html.Element Function(int viewId) viewFactory) { + return ui_web.platformViewRegistry + .registerViewFactory(viewTypeId, viewFactory); + } +} diff --git a/flutter_inappwebview_web/lib/web/web_platform.dart b/flutter_inappwebview_web/lib/web/web_platform.dart index 3cca5ab0..de74ea71 100644 --- a/flutter_inappwebview_web/lib/web/web_platform.dart +++ b/flutter_inappwebview_web/lib/web/web_platform.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:ui_web'; import '../src/inappwebview_platform.dart'; import 'headless_inappwebview_manager.dart'; import 'web_platform_manager.dart'; @@ -9,6 +8,8 @@ import 'in_app_web_view_web_element.dart'; import 'platform_util.dart'; import 'package:js/js.dart'; +import 'shims/platform_view_registry.dart' show platformViewRegistry; + /// Builds an iframe based WebView. /// /// This is used as the default implementation for `WebView` on web. diff --git a/flutter_inappwebview_web/pubspec.yaml b/flutter_inappwebview_web/pubspec.yaml index 1e0119e9..b9de20d6 100644 --- a/flutter_inappwebview_web/pubspec.yaml +++ b/flutter_inappwebview_web/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inappwebview_web description: Web implementation of the flutter_inappwebview plugin. -version: 1.0.2 +version: 1.0.3 homepage: https://inappwebview.dev/ repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_web issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues