Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

wkwebview was invalidated error when using js in disappearing method

snowlsnowl Member ✭✭
edited December 2020 in Xamarin.Forms

I need to take page content before page close so I override OnDisappearing method and I use EvaluateJavaScriptAsync("document.documentElement.innerHTML"). But I take wkwebview was invalidated error because of the webview destructed.I wait EvaluateJavaScriptAsync but not work. How can I take page content just before page close ?

`
async protected override void OnDisappearing()
{

            bookmark_check();
            if (bkmrk) {

               var content = await sayfa.EvaluateJavaScriptAsync("document.documentElement.innerHTML");
               await DisplayAlert("ok",content,"ok");

            }

        }

`

Answers

  • snowlsnowl Member ✭✭

    Any help ?

  • ColeXColeX Member, Xamarin Team Xamurai

    To avoid the error I suggest you move the logic into Navigated of WebView , and then get the value anywhere(in OnDisappearing method) .

       webview.Navigated += async (sender, args) =>
            {
                //content is global variable
                content = await webview.EvaluateJavaScriptAsync("document.documentElement.innerHTML");
            };
    

    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

Sign In or Register to comment.