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

This commit is contained in:
Lorenzo Pichilli 2023-12-06 02:19:40 +01:00
parent beb827858f
commit 7bb70eb7d9
16 changed files with 121 additions and 60 deletions

View File

@ -24,13 +24,14 @@ labels: bug
## Environment ## Environment
| Technology | Version | | Technology | Version |
|-----------------| ------------- | |-----------------------| ------------- |
| Flutter version | | | Flutter version | |
| Plugin version | | | Plugin version | |
| Android version | | | Android version | |
| iOS version | | | iOS version | |
| macOS version | | | macOS version | |
| Xcode version | | | Xcode version | |
| Google Chrome version | |
Device information: <!-- Manufacturer and model --> Device information: <!-- Manufacturer and model -->

View File

@ -4,7 +4,7 @@ version: 1.1.1
homepage: https://github.com/pichillilorenzo/flutter_inappwebview homepage: https://github.com/pichillilorenzo/flutter_inappwebview
environment: environment:
sdk: ">=2.15.0 <4.0.0" sdk: ">=2.17.0 <4.0.0"
dev_dependencies: dev_dependencies:
test: ^1.21.6 test: ^1.21.6

View File

@ -4,17 +4,17 @@ version: 1.0.0
publish_to: none publish_to: none
environment: environment:
sdk: ">=2.14.0 <3.0.0" sdk: ">=2.17.0 <4.0.0"
flutter: ">=2.5.0" flutter: ">=3.0.0"
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
build: ^2.4.0 build: 2.3.1
source_gen: ^1.3.1 source_gen: ^1.3.1
flutter_inappwebview_internal_annotations: ^1.1.1 flutter_inappwebview_internal_annotations: ^1.1.1
dev_dependencies: dev_dependencies:
build_runner: ^2.4.2 build_runner: 2.3.3
build_test: ^2.1.7 build_test: ^2.1.7
test: ^1.24.2 test: ^1.24.2

View File

@ -30,7 +30,7 @@ dev_dependencies:
flutter_driver: flutter_driver:
sdk: flutter sdk: flutter
flutter_lints: ^2.0.1 flutter_lints: ^2.0.1
build_runner: ^2.2.1 build_runner: 2.3.3
generators: generators:
path: ../dev_packages/generators path: ../dev_packages/generators

View File

@ -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 publish_to: 'none' # Remove this line if you wish to publish to pub.dev
environment: 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. # Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions # To automatically upgrade your package dependencies to the latest versions

View File

@ -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 publish_to: 'none' # Remove this line if you wish to publish to pub.dev
environment: 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. # Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions # To automatically upgrade your package dependencies to the latest versions

View File

@ -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 publish_to: 'none' # Remove this line if you wish to publish to pub.dev
environment: 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. # Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions # To automatically upgrade your package dependencies to the latest versions

View File

@ -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 ## 1.0.2
- Updated `flutter_inappwebview_platform_interface` version dependency to `1.0.5` - Updated `flutter_inappwebview_platform_interface` version dependency to `1.0.5`

View File

@ -1,14 +1,22 @@
# Generated by pub # Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile # See https://dart.dev/tools/pub/glossary#lockfile
packages: packages:
archive:
dependency: transitive
description:
name: archive
sha256: "80e5141fafcb3361653ce308776cfd7d45e6e9fbb429e14eec571382c0c5fecb"
url: "https://pub.dev"
source: hosted
version: "3.3.2"
async: async:
dependency: transitive dependency: transitive
description: description:
name: async name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.11.0" version: "2.10.0"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
@ -21,10 +29,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: characters name: characters
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.3.0" version: "1.2.1"
clock: clock:
dependency: transitive dependency: transitive
description: description:
@ -37,10 +45,18 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: collection name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
url: "https://pub.dev" url: "https://pub.dev"
source: hosted 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: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
@ -130,50 +146,50 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: js name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.6.7" version: "0.6.5"
lints: lints:
dependency: transitive dependency: transitive
description: description:
name: lints name: lints
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.1" version: "2.0.1"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.12.16" version: "0.12.13"
material_color_utilities: material_color_utilities:
dependency: transitive dependency: transitive
description: description:
name: material_color_utilities name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.5.0" version: "0.2.0"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.9.1" version: "1.8.0"
path: path:
dependency: transitive dependency: transitive
description: description:
name: path name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.8.3" version: "1.8.2"
platform: platform:
dependency: transitive dependency: transitive
description: description:
@ -186,10 +202,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: plugin_platform_interface name: plugin_platform_interface
sha256: f4f88d4a900933e7267e2b353594774fc0d07fb072b47eedcd5b54e1ea3269f8 sha256: da3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.7" version: "2.1.6"
process: process:
dependency: transitive dependency: transitive
description: description:
@ -207,10 +223,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: source_span name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.10.0" version: "1.9.1"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
@ -255,10 +271,18 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
url: "https://pub.dev" url: "https://pub.dev"
source: hosted 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: vector_math:
dependency: transitive dependency: transitive
description: description:
@ -271,26 +295,18 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: vm_service name: vm_service
sha256: c620a6f783fa22436da68e42db7ebbf18b8c44b9a46ab911f666ff09ffd9153f sha256: e7fb6c2282f7631712b69c19d1bff82f3767eea33a2321c14fa59ad67ea391c7
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "11.7.1" version: "9.4.0"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
webdriver: webdriver:
dependency: transitive dependency: transitive
description: description:
name: webdriver name: webdriver
sha256: "3c923e918918feeb90c4c9fdf1fe39220fa4c0e8e2c0fffaded174498ef86c49" sha256: ef67178f0cc7e32c1494645b11639dd1335f1d18814aa8435113a92e9ef9d841
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.2" version: "3.0.1"
sdks: sdks:
dart: ">=3.1.4 <4.0.0" dart: ">=2.19.0 <3.0.0"
flutter: ">=3.0.0" flutter: ">=3.0.0"

View File

@ -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 publish_to: 'none' # Remove this line if you wish to publish to pub.dev
environment: 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. # Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions # To automatically upgrade your package dependencies to the latest versions

View File

@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
import 'dart:html'; import 'dart:html';
import 'dart:js' as js; import 'dart:js' as js;
import 'dart:developer';
import 'headless_inappwebview_manager.dart'; import 'headless_inappwebview_manager.dart';
import 'web_platform_manager.dart'; import 'web_platform_manager.dart';
@ -51,8 +52,8 @@ class InAppWebViewWebElement implements Disposable {
try { try {
return await handleMethodCall(call); return await handleMethodCall(call);
} on Error catch (e) { } on Error catch (e) {
print(e); log(e.toString(),
print(e.stackTrace); name: runtimeType.toString(), error: e, stackTrace: e.stackTrace);
} }
}); });
@ -291,7 +292,17 @@ class InAppWebViewWebElement implements Disposable {
(urlRequest.headers == null || urlRequest.headers!.isEmpty)) { (urlRequest.headers == null || urlRequest.headers!.isEmpty)) {
iframe.src = urlRequest.url.toString(); iframe.src = urlRequest.url.toString();
} else { } else {
try {
iframe.src = _convertHttpResponseToData(await _makeRequest(urlRequest)); 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();
}
}
} }
} }

View File

@ -0,0 +1,2 @@
export 'platform_view_registry_dart_ui.dart'
if (dart.library.ui_web) 'platform_view_registry_dart_ui_web.dart';

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -1,5 +1,4 @@
import 'dart:async'; import 'dart:async';
import 'dart:ui_web';
import '../src/inappwebview_platform.dart'; import '../src/inappwebview_platform.dart';
import 'headless_inappwebview_manager.dart'; import 'headless_inappwebview_manager.dart';
import 'web_platform_manager.dart'; import 'web_platform_manager.dart';
@ -9,6 +8,8 @@ import 'in_app_web_view_web_element.dart';
import 'platform_util.dart'; import 'platform_util.dart';
import 'package:js/js.dart'; import 'package:js/js.dart';
import 'shims/platform_view_registry.dart' show platformViewRegistry;
/// Builds an iframe based WebView. /// Builds an iframe based WebView.
/// ///
/// This is used as the default implementation for `WebView` on web. /// This is used as the default implementation for `WebView` on web.

View File

@ -1,6 +1,6 @@
name: flutter_inappwebview_web name: flutter_inappwebview_web
description: Web implementation of the flutter_inappwebview plugin. description: Web implementation of the flutter_inappwebview plugin.
version: 1.0.2 version: 1.0.3
homepage: https://inappwebview.dev/ homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_web repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_web
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues