Is there any way to parse html created with javascript in flutter?

I would like to use metadata_fetch package to get the OGP. The implementation of this package uses the html (parse) package. And it worked for most of the web pages. However, there are some web pages, like this one, that cannot be fetched. I think this was because the html was generated by javascript. Is there any way to parse such a page as well?


You should be able to create a webview_flutter and inject some sort of Javascript that would walk the DOM for you and serialize it for return, which of course would happen after the page javascript has already built up the DOM. I haven't done that, but it might be a fun project.

EDIT: it might be as simple as capturing the string response of document.firstElementChild.outerHTML.


For the benefit of others, here's a source I made based on an idea from @Randal Schwartz.

const String url_unext = 'https://video.unext.jp/title/SID0050925';
WebViewController _controller;
Stack(
  children: [
    WebView(
      onWebViewCreated: (controller) {
        _controller = controller;
      },
      javascriptMode: JavascriptMode.unrestricted,
      initialUrl: url_unext,
      onPageFinished: (_) async {
        html = await _controller.evaluateJavascript("window.document.firstElementChild.outerHTML;");
        // Use Metadata_fetch to parse
        final data = getOpenGraphDataFromResponse(html);
        print(data);
      },
    ),
    // else widget here
    Container(),
  ],
),

However, I am concerned about running a malicious script. If there is a better way, please let me know. I'm looking into the possibility of using oembed. Once again, thank you very much, @Randal Schwartz.