adrianflutur / webviewx

A feature-rich cross-platform webview using webview_flutter for mobile and iframe for web. JS interop-ready.
MIT License
83 stars 121 forks source link

Larger HTML files cause exception #38

Open pavel604 opened 3 years ago

pavel604 commented 3 years ago

I was able to load small HTML markup from string, but failed with a 20kb file. This error is thrown about half way through the file, after page started loading. (The same file works fine in webview plugin)

Code loading the file:

Future<void> getHtml() async {
    String c = await rootBundle.loadString('assets/index.html');
    webviewController.loadContent(c, SourceType.html);
  }

Exception thrown:

════════ Exception caught by foundation library ════════════════════════════════
The following RangeError was thrown while dispatching notifications for WebViewXController:
RangeError (end): Invalid value: Not in inclusive range 0..19853: -1

When the exception was thrown, this was the stack
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49  throw_
dart-sdk/lib/core/errors.dart 338:9                                           checkValidRange
dart-sdk/lib/_internal/js_dev_runtime/private/js_string.dart 168:22           substring]
packages/webviewx/src/utils/html_utils.dart 208:36                            embedInHtmlSource
packages/webviewx/src/utils/html_utils.dart 173:12                            embedJsInHtmlSource
packages/webviewx/src/utils/html_utils.dart 235:12                            embedWebIframeJsConnector
packages/webviewx/src/utils/html_utils.dart 64:14                             preprocessSource
packages/webviewx/src/view/impl/web.dart 420:35                               [_updateSource]
packages/webviewx/src/view/impl/web.dart 381:5                                [_handleChange]
packages/flutter/src/foundation/change_notifier.dart 308:24                   notifyListeners
packages/webviewx/src/controller/impl/web.dart 265:5                          [_notifyWidget]
packages/webviewx/src/controller/impl/web.dart 110:5                          loadContent
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5            _async
packages/webviewx/src/controller/impl/web.dart 82:27                          loadContent
packages/wsm2/src/map/map_view.dart 108:23                                    getHtml
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1687:54                                          runUnary
dart-sdk/lib/async/future_impl.dart 160:18                                    handleValue
dart-sdk/lib/async/future_impl.dart 767:44                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 796:13                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 602:5                                     [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 640:7                                     callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15           <fn>
The WebViewXController sending notification was: Instance of 'WebViewXController'
════════════════════════════════════════════════════════════════════════════════
adrianflutur commented 3 years ago

Hi, I'm not sure what causes this. It may be some invalid HTML attribute or tag. Can you attach the HTML source you are trying to load? Thanks

pavel604 commented 3 years ago

I think it's just the length limit of [src] attribute of [iframe] tag. nothing we can do.

adrianflutur commented 3 years ago

Actually the package loads HTML using the srcDoc attribute. It only loads URLs (non-bypass) using src. But still, pretty weird, didn't happen to me so far and the package actually loads entire webpages into the iframe when using the SourceType.urlBypass option. Are you sure it's not some other issue here?