Xpra-org / xpra-html5

HTML5 client for Xpra
Mozilla Public License 2.0
209 stars 55 forks source link

Add OffscreenCanvas to Firefox>=108 and Safari>=16.4 #258

Closed jhgoebbert closed 1 year ago

jhgoebbert commented 1 year ago

Support for OffscreenCanvas got added to Firefox and Safari now: https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas#browser_compatibility

I enabled it and run the xpra-html5 client on Firefox 114 (Windows10 ) without flickering.

It could be worth enabling it beside Chrome now also on Firefox>=108 and Safari>=16.4 https://github.com/Xpra-org/xpra-html5/blob/master/html5/js/OffscreenDecodeWorkerHelper.js#L15

[..]
  // OffscreenCanvas supported since v.16.4
  isSafariVersionSupported() {
    var match = navigator.userAgent.match(/version\/(\d+\.\d+)/i);
    if (match && match[1]) {
      var version = parseFloat(match[1]);
      return version >= 16.4;
    }
    return false;
  },

  // OffscreenCanvas supported since v.105 (with fixed added for 107/108)
  isFirefoxVersionSupported() {
    var match = navigator.userAgent.match(/firefox\/(\d+)/i);
    if (match && match[1]) {
      var version = parseInt(match[1], 10);
      return version >= 108;
    }
    return false;
  },

  isAvailable() {
    var isSafari = navigator.userAgent.toLowerCase().includes("safari");
    if (isSafari && !this.isSafariVersionSupported()) {
      return false;
    }

    var isFirefox = navigator.userAgent.toLowerCase().includes("firefox");
    if (isFirefox && this.isFirefoxVersionSupported()) {
      return false;
    }

    if (typeof OffscreenCanvas !== "undefined") {
      //we also need the direct constructor:
      try {
        new OffscreenCanvas(256, 256);
        return true;
      } catch (error) {
        console.warn("unable to instantiate an offscreen canvas:", error);
      }
    }
    console.warn(
      "Offscreen decoding is not available. Please consider using " +
      "Google Chrome, Firefox >= 108 or Safari >= 16.4 for better performance."
    );
    return false;
  },
};
totaam commented 1 year ago

Applied. Thanks!

I like the idea of restricting to Firefox 108 or later, because when we tested with earlier versions, it didn't work reliably. As for Safari, does that somehow fix #227?

jhgoebbert commented 1 year ago

Hmm ... I see that in https://github.com/Xpra-org/xpra-html5/issues/227 Safari 16.5 was already tested and not working reliable. So you might need to keep Safari disabled then 😞 I only tested Firefox.

totaam commented 1 year ago

Done: c70634686abb67d2522837e7ea9a463f870a4281

jhgoebbert commented 1 year ago

This bug in WebKit https://github.com/Xpra-org/xpra-html5/issues/227#issuecomment-1624204221 might be the reason why it is not yet working for Safari. :thinking: but hopefully working soon.