Browse Source

Inspector - Popup mode disabled for edge, as it cannot be created for security reasons

Temechon 8 years ago
parent
commit
842dee1477

+ 43 - 36
inspector/src/Inspector.ts

@@ -35,8 +35,8 @@ module INSPECTOR {
             Inspector.DOCUMENT = window.document;   
             Inspector.WINDOW = window;                       
             
-            // POPUP MODE if parent is defined
-            if (popup) {    
+            // POPUP MODE
+            if (popup) { 
                 // Build the inspector in the given parent
                 this.openPopup(true);// set to true in order to NOT dispose the inspector (done in openPopup), as it's not existing yet
             } else {        
@@ -137,8 +137,10 @@ module INSPECTOR {
                 Helpers.SEND_EVENT('resize');
             }
 
-            // Refresh the inspector
-            this.refresh();
+            // Refresh the inspector if the browser is not edge
+            if (!Helpers.IsBrowserEdge()) {
+                this.refresh();
+            }
         }
         
         /**
@@ -249,38 +251,43 @@ module INSPECTOR {
          * Set 'firstTime' to true if there is no inspector created beforehands
          */
         public openPopup(firstTime?:boolean) {    
-            // Create popup
-            let popup = window.open('', 'Babylon.js INSPECTOR', 'toolbar=no,resizable=yes,menubar=no,width=750,height=1000');
-            popup.document.title = 'Babylon.js INSPECTOR';
-            // Get the inspector style      
-            let styles = Inspector.DOCUMENT.querySelectorAll('style');
-            for (let s = 0; s<styles.length; s++) {
-                popup.document.body.appendChild(styles[s].cloneNode(true));              
-            } 
-            let links = document.querySelectorAll('link');
-            for (let l = 0; l<links.length; l++) {
-                let link  = popup.document.createElement("link");
-                link.rel  = "stylesheet";
-                link.href = (links[l] as HTMLLinkElement).href;
-                popup.document.head.appendChild(link);              
-            } 
-            // Dispose the right panel if existing
-            if (!firstTime) {
-                this.dispose();
-            }
-            // set the mode as popup
-            this._popupMode = true;
-            // Save the HTML document
-            Inspector.DOCUMENT = popup.document;
-            Inspector.WINDOW = popup;
-            // Build the inspector wrapper
-            this._c2diwrapper  = Helpers.CreateDiv('insp-wrapper', popup.document.body);
-            // add inspector     
-            let inspector      = Helpers.CreateDiv('insp-right-panel', this._c2diwrapper);
-            // and build it in the popup  
-            this._buildInspector(inspector); 
-            // Rebuild it
-            this.refresh();              
+            
+            if (Helpers.IsBrowserEdge()) {
+                console.warn('Inspector - Popup mode is disabled in Edge, as the popup DOM cannot be updated from the main window for security reasons');
+            } else {
+                // Create popup
+                let popup = window.open('', 'Babylon.js INSPECTOR', 'toolbar=no,resizable=yes,menubar=no,width=750,height=1000');
+                popup.document.title = 'Babylon.js INSPECTOR';
+                // Get the inspector style      
+                let styles = Inspector.DOCUMENT.querySelectorAll('style');
+                for (let s = 0; s<styles.length; s++) {
+                    popup.document.body.appendChild(styles[s].cloneNode(true));              
+                } 
+                let links = document.querySelectorAll('link');
+                for (let l = 0; l<links.length; l++) {
+                    let link  = popup.document.createElement("link");
+                    link.rel  = "stylesheet";
+                    link.href = (links[l] as HTMLLinkElement).href;
+                    popup.document.head.appendChild(link);              
+                } 
+                // Dispose the right panel if existing
+                if (!firstTime) {
+                    this.dispose();
+                }
+                // set the mode as popup
+                this._popupMode = true;
+                // Save the HTML document
+                Inspector.DOCUMENT = popup.document;
+                Inspector.WINDOW = popup;
+                // Build the inspector wrapper
+                this._c2diwrapper  = Helpers.CreateDiv('insp-wrapper', popup.document.body);
+                // add inspector     
+                let inspector      = Helpers.CreateDiv('insp-right-panel', this._c2diwrapper);
+                // and build it in the popup  
+                this._buildInspector(inspector); 
+                // Rebuild it
+                this.refresh(); 
+            }             
         }
     }
 }

+ 9 - 0
inspector/src/helpers/Helpers.ts

@@ -36,6 +36,15 @@ module INSPECTOR {
             } 
             return false;
         }
+        
+        /**
+         * Returns true if the user browser is edge.
+         */
+        public static IsBrowserEdge() : boolean {
+            //Detect if we are running on a faulty buggy OS.
+            var regexp = /Edge/
+            return regexp.test(navigator.userAgent);
+        }
 
         /** 
          * Returns the name of the type of the given object, where the name 

+ 3 - 2
inspector/src/tools/Toolbar.ts

@@ -26,8 +26,9 @@
             // Pick object
             this._tools.push(new PickTool(this._div, this._inspector));
             
-            // Add the popup mode only if the inspector is not in popup mode
-            if (!this._inspector.popupMode) {
+            // Add the popup mode only if the inspector is not in popup mode and if the brower is not edge
+            // Edge is 
+            if (!this._inspector.popupMode && !Helpers.IsBrowserEdge()) {
                 this._tools.push(new PopupTool(this._div, this._inspector));
             }
             // Pause schedule

+ 1 - 1
inspector/test/index.js

@@ -18,7 +18,7 @@ var Test = (function () {
         this._initScene();
         // BABYLON.DebugLayer.InspectorURL = 'http://localhost:1338/dist/preview release/inspector/babylon.inspector.js';
         window.addEventListener('click', () => {
-            this.scene.debugLayer.show();
+            this.scene.debugLayer.show(true);
         })
         this.scene.executeWhenReady(function () {
             _this._initGame();