Skip to content

[web][canvaskit] Images Disappear after leaving Fullscreen #91881

@creativecreatorormaybenot

Description

Bug

On stable, images on web turn black after leaving a fullscreen video (#89037).
On master, the images disappear.

Behavior

When exiting a fullscreen video on web, all Images disappear, see this screen recording:

2021-10-15.07-21-21.mp4

Reproducible sample

Here is a reproducible sample app for this problem:

Click to expand sample code & version

index.html

<!DOCTYPE html>
<html>
<head>
  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    For more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

    This is a placeholder for base href that will be replaced by the value of
    the `--base-href` argument provided to `flutter build`.
  -->
  <base href="$FLUTTER_BASE_HREF">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- iOS meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="bug2">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <title>bug2</title>
  <link rel="manifest" href="manifest.json">

  <script src="https://cdn.jwplayer.com/libraries/m9EWsAaw.js"></script>
</head>
<body>
  <!-- This script installs service_worker.js to provide PWA functionality to
       application. For more information, see:
       https://developers.google.com/web/fundamentals/primers/service-workers -->
  <script>
    var serviceWorkerVersion = null;
    var scriptLoaded = false;
    function loadMainDartJs() {
      if (scriptLoaded) {
        return;
      }
      scriptLoaded = true;
      var scriptTag = document.createElement('script');
      scriptTag.src = 'main.dart.js';
      scriptTag.type = 'application/javascript';
      document.body.append(scriptTag);
    }

    if ('serviceWorker' in navigator) {
      // Service workers are supported. Use them.
      window.addEventListener('load', function () {
        // Wait for registration to finish before dropping the <script> tag.
        // Otherwise, the browser will load the script multiple times,
        // potentially different versions.
        var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
        navigator.serviceWorker.register(serviceWorkerUrl)
          .then((reg) => {
            function waitForActivation(serviceWorker) {
              serviceWorker.addEventListener('statechange', () => {
                if (serviceWorker.state == 'activated') {
                  console.log('Installed new service worker.');
                  loadMainDartJs();
                }
              });
            }
            if (!reg.active && (reg.installing || reg.waiting)) {
              // No active web worker and we have installed or are installing
              // one for the first time. Simply wait for it to activate.
              waitForActivation(reg.installing || reg.waiting);
            } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
              // When the app updates the serviceWorkerVersion changes, so we
              // need to ask the service worker to update.
              console.log('New service worker available.');
              reg.update();
              waitForActivation(reg.installing);
            } else {
              // Existing service worker is still good.
              console.log('Loading app from service worker.');
              loadMainDartJs();
            }
          });

        // If service worker doesn't succeed in a reasonable amount of time,
        // fallback to plaint <script> tag.
        setTimeout(() => {
          if (!scriptLoaded) {
            console.warn(
              'Failed to load app from service worker. Falling back to plain <script> tag.',
            );
            loadMainDartJs();
          }
        }, 4000);
      });
    } else {
      // Service workers not supported. Just drop the <script> tag.
      loadMainDartJs();
    }
  </script>

  <script>
    new MutationObserver(function(mutations, observer) {
      mutations.forEach(function(mutation) {
        mutation.addedNodes.forEach(function(node) {
          if (node.nodeType == 1) {
            var target = node.querySelector('#jw-player-target');
            if (target != null) {
              // Init jwplayer into target...
              jwplayer(target).setup({
                playlist: 'https://cdn.jwplayer.com/v2/media/tkM1zvBq',
                autostart: 'viewable'
              });
            }
          }
        });
      });
    }).observe(window.document.body, {
      attributes: false,
      childList: true,
      subtree: true,
    });
  </script>
</body>
</html>

main.dart

import 'dart:html' as html;
import 'dart:ui' as ui;

import 'package:flutter/material.dart';

const String viewType = 'jw-player-view';

void main() {
  final div = html.DivElement()..id = 'jw-player-target';
  // We surround our JW Player <div> with *another* div because
  // jwplayer().setup() will modify the div properties, which will break
  // Flutter's platform view. Therefore, we simply wrap the div that JW
  // Player interacts with with another div that Flutter can interact with :)
  final container = html.DivElement()
    ..style.width = '100%'
    ..style.height = '100%'
    ..append(div);

  ui.platformViewRegistry.registerViewFactory(
    viewType,
    (int viewId) => container,
  );

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Column(
              children: [
                Image.network(
                  'https://picsum.photos/600/200?random=2',
                ),
                Image.network(
                  'https://upload.wikimedia.org/wikipedia/commons/thumb/'
                  '1/17/Google-flutter-logo.png/799px-Google-flutter-logo.png',
                  width: 600,
                ),
                Image.network(
                  'https://picsum.photos/600/200?random=1',
                ),
              ],
            ),
            const SizedBox(
              width: 6e2,
              child: AspectRatio(
                aspectRatio: 16 / 9,
                child: HtmlElementView(viewType: viewType),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Versions

Flutter 2.6.0-12.0.pre.364 • channel master • https://github.com/flutter/flutter.git
Framework • revision 2f4e3ce5b0 (2 hours ago) • 2021-10-14 22:38:05 -0700
Engine • revision 8034050e78
Tools • Dart 2.15.0 (build 2.15.0-217.0.dev)

Problem

In one of our apps, videos are one of the main parts of the application. This is why #89037 on stable breaks this app.
I figured I could make a CP request for #89037. However, now I realized that it is not working on master either, so it seems that from stablemaster web is in a broken state in this regard and the only workaround is using an older version of Flutter.

Metadata

Metadata

Labels

assigned for triageissue is assigned to a domain expert for further triagec: regressionIt was better in the past than it is nowe: web_canvaskitCanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Webengineflutter/engine related. See also e: labels.found in release: 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions