From b190d02925ada60b71851b69f25f03c19aa2d021 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Tue, 14 Nov 2023 23:13:02 +0100 Subject: [PATCH] fix #1841 --- CHANGELOG.md | 1 + lib/assets/web/web_support.js | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca6640a6..f09013d5 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Added support for Android `WebViewFeature.isStartupFeatureSupported`, `WebViewFeature.STARTUP_FEATURE_SET_DIRECTORY_BASE_PATHS`, `WebViewFeature.STARTUP_FEATURE_SET_DATA_DIRECTORY_SUFFIX`, `WebViewFeature.WEB_MESSAGE_ARRAY_BUFFER` - Added `WebMessage.type` property - Fixed "iOS EXC_BAD_ACCESS crash on kill app with InAppWebView keyboard open" [#1837](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1837) +- Fixed "Flutter Web - TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'. error" [#1841](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1841) ### BREAKING CHANGES diff --git a/lib/assets/web/web_support.js b/lib/assets/web/web_support.js index 98507574..0cac0f45 100644 --- a/lib/assets/web/web_support.js +++ b/lib/assets/web/web_support.js @@ -139,18 +139,21 @@ window.flutter_inappwebview = { } var initialTitle = iframe.contentDocument.title; + var titleEl = iframe.contentDocument.querySelector('title'); webView.documentTitle = initialTitle; window.flutter_inappwebview.nativeCommunication('onTitleChanged', viewId, [initialTitle]); - new MutationObserver(function(mutations) { - var title = mutations[0].target.innerText; - if (title != webView.documentTitle) { - webView.documentTitle = title; - window.flutter_inappwebview.nativeCommunication('onTitleChanged', viewId, [title]); - } - }).observe( - iframe.contentDocument.querySelector('title'), - { subtree: true, characterData: true, childList: true } - ); + if (titleEl != null) { + new MutationObserver(function(mutations) { + var title = mutations[0].target.innerText; + if (title != webView.documentTitle) { + webView.documentTitle = title; + window.flutter_inappwebview.nativeCommunication('onTitleChanged', viewId, [title]); + } + }).observe( + titleEl, + { subtree: true, characterData: true, childList: true } + ); + } var oldPixelRatio = iframe.contentWindow.devicePixelRatio; iframe.contentWindow.addEventListener('resize', function (e) {