airsdk / Adobe-Runtime-Support

Report, track and discuss issues in Adobe AIR. Monitored by Adobe - and HARMAN - and maintained by the AIR community.
206 stars 11 forks source link

[Windows] Second instance of `StageWebView` with `UseWebView2` display "WebView2 Host" message with background #3577

Open itlancer opened 5 days ago

itlancer commented 5 days ago

Problem Description

Second (and susequent) instance of StageWebView with UseWebView2 display "WebView2 Host" message with background for Windows devices. It breaks UX in a lot of cases and cause "artifacts" on window resizing.

Tested with multiple AIR versions, even with latest AIR 51.1.2.2 with different Windows 10 devices, different WebView2 versions, different AIR applications with different architectures (32/64-bit) and different privileges. Not sure about Windows 11. Same issue in all cases. There is no such issue with first StageWebView. There is no such issue with other platforms.

Related issues: https://github.com/airsdk/Adobe-Runtime-Support/issues/2946 https://github.com/airsdk/Adobe-Runtime-Support/issues/2920 https://github.com/airsdk/Adobe-Runtime-Support/issues/2852 https://github.com/airsdk/Adobe-Runtime-Support/issues/2832 https://github.com/airsdk/Adobe-Runtime-Support/issues/2831 https://github.com/airsdk/Adobe-Runtime-Support/issues/1854 https://github.com/airsdk/Adobe-Runtime-Support/issues/1493 https://github.com/airsdk/Adobe-Runtime-Support/issues/1492 https://github.com/airsdk/Adobe-Runtime-Support/issues/1428 https://github.com/airsdk/Adobe-Runtime-Support/issues/223 https://github.com/airsdk/Adobe-Runtime-Support/issues/143

Steps to Reproduce

Launch code below with any Windows device and resize application window fast. Two StageWebView instances always will be at the center of window. Application example with sources and demonstration video attached. windows_stagewebview_usewebview2_host_message_bug.zip

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.media.StageWebView;
    import flash.geom.Rectangle;
    import flash.events.NativeWindowBoundsEvent;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;

    public class WindowsStageWebViewUseWebView2HostMessageBug extends Sprite {
        private var stageWebView:StageWebView;
        private var stageWebView2:StageWebView;

        public function WindowsStageWebViewUseWebView2HostMessageBug() {
            addEventListener(Event.ADDED_TO_STAGE, addedToStage);
        }

        private function addedToStage(e:Event):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;

            var rect:Rectangle = stage.nativeWindow.bounds;
            var contentsScaleFactor:Number = stage.contentsScaleFactor;

            stageWebView = new StageWebView({mediaPlaybackRequiresUserAction:false});
            stageWebView.loadURL("https://www.bbc.com/");
            stageWebView.viewPort = new Rectangle(0, rect.height / 4 * contentsScaleFactor, rect.width / 2 * contentsScaleFactor, rect.height / 2 * contentsScaleFactor);
            stageWebView.stage = stage;

            stageWebView2 = new StageWebView({mediaPlaybackRequiresUserAction:false});
            stageWebView2.loadURL("https://airsdk.harman.com/");
            stageWebView2.viewPort = new Rectangle(rect.width / 2 * contentsScaleFactor, rect.height / 4 * contentsScaleFactor, rect.width / 2 * contentsScaleFactor, rect.height / 2 * contentsScaleFactor);
            stageWebView2.stage = stage;

            stage.nativeWindow.addEventListener(NativeWindowBoundsEvent.RESIZE, windowResize);
        }

        private function windowResize(e:NativeWindowBoundsEvent):void {
            var rect:Rectangle = e.afterBounds;
            var contentsScaleFactor:Number = stage.contentsScaleFactor;

            stageWebView.viewPort = new Rectangle(0, rect.height / 4 * contentsScaleFactor, rect.width / 2 * contentsScaleFactor, rect.height / 2 * contentsScaleFactor);
            stageWebView2.viewPort = new Rectangle(rect.width / 2 * contentsScaleFactor, rect.height / 4 * contentsScaleFactor, rect.width / 2 * contentsScaleFactor, rect.height / 2 * contentsScaleFactor);
        }
    }
}

Actual Result: Below second (right) instance of StageWebView you will see "WebView2 Host" message with gray background. Also you can notice some artifacts and sometimes StageWebView instance will be displayed partially out of window: image

Video demonstration:

https://github.com/user-attachments/assets/3cbcf52b-91cc-410e-874b-855ff3e2e855

Expected Result: Second (right) instance of StageWebView will be displayed without "WebView2 Host" message, gray background and without artifacts.

Known Workarounds

none