From 12cccede513704a61e71c88021ecec075f6bdf5e Mon Sep 17 00:00:00 2001 From: jiang <1446935823@qq.com> Date: Thu, 11 Apr 2024 22:27:35 +0000 Subject: [PATCH 01/14] Added resize browser mode --- app/locale/zh_CN.json | 1 + app/ui.js | 13 ++++++++++++- core/rfb.js | 23 +++++++++++++++++++++++ vnc.html | 1 + 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/locale/zh_CN.json b/app/locale/zh_CN.json index f0aea9af3..70c01161e 100644 --- a/app/locale/zh_CN.json +++ b/app/locale/zh_CN.json @@ -52,6 +52,7 @@ "None": "无", "Local Scaling": "本地缩放", "Remote Resizing": "远程调整大小", + "Resizing browser": "调整浏览器大小", "Advanced": "高级", "Repeater ID:": "中继站 ID", "WebSocket": "WebSocket", diff --git a/app/ui.js b/app/ui.js index f27dfe28e..86ebdeed0 100644 --- a/app/ui.js +++ b/app/ui.js @@ -1066,6 +1066,7 @@ const UI = { UI.rfb.clipViewport = UI.getSetting('view_clip'); UI.rfb.scaleViewport = UI.getSetting('resize') === 'scale'; UI.rfb.resizeSession = UI.getSetting('resize') === 'remote'; + UI.rfb.resizeBrowser = UI.getSetting('resize') === 'browser'; UI.rfb.qualityLevel = parseInt(UI.getSetting('quality')); UI.rfb.compressionLevel = parseInt(UI.getSetting('compression')); UI.rfb.showDotCursor = UI.getSetting('show_dot'); @@ -1319,6 +1320,7 @@ const UI = { UI.rfb.scaleViewport = UI.getSetting('resize') === 'scale'; UI.rfb.resizeSession = UI.getSetting('resize') === 'remote'; + UI.rfb.resizeBrowser = UI.getSetting('resize') === 'browser'; }, /* ------^------- @@ -1360,7 +1362,16 @@ const UI = { UI.enableSetting('view_clip'); UI.rfb.clipViewport = UI.getSetting('view_clip'); } - + + // Determines whether it is a window.open window + // as window.open(\'/vnc/?token=token&autoconnect=1&resize=browser\',\'_blank\',\'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=800,height=420\'); + var win = window.opener; + if(win == null){ + document.getElementById("noVNC_setting_browser_resize").disabled = true; + }else{ + document.getElementById("noVNC_setting_browser_resize").disabled = false; + } + // Changing the viewport may change the state of // the dragging button UI.updateViewDrag(); diff --git a/core/rfb.js b/core/rfb.js index f2deb0e7b..851769d94 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -290,6 +290,7 @@ export default class RFB extends EventTargetMixin { this._clippingViewport = false; this._scaleViewport = false; this._resizeSession = false; + this._resizeBrowser = false; this._showDotCursor = false; if (options.showDotCursor !== undefined) { @@ -352,6 +353,14 @@ export default class RFB extends EventTargetMixin { } } + get resizeBrowser() { return this._resizeBrowser; } + set resizeBrowser(resize) { + this._resizeBrowser = resize; + if(this._resizeBrowser && (this._rfbConnectionState === 'connected')){ + this._updateBrowserWindows(this._fbWidth, this._fbHeight); + } + } + get resizeSession() { return this._resizeSession; } set resizeSession(resize) { this._resizeSession = resize; @@ -2863,9 +2872,23 @@ export default class RFB extends EventTargetMixin { this._fbWidth, this._fbHeight); } + _updateBrowserWindows(width, height) { + if(this._resizeBrowser && (this._rfbConnectionState === 'connected')){ + var fbWidth = width; + var fbHeight = height; + var bodyWidth = document.body.clientWidth; + var bodyHeight = document.body.clientHeight; + if((fbWidth != 0) && (fbHeight != 0)){ + window.resizeBy(fbWidth - bodyWidth,fbHeight - bodyHeight); + } + } + } + _resize(width, height) { this._fbWidth = width; this._fbHeight = height; + + this._updateBrowserWindows(width, height); this._display.resize(this._fbWidth, this._fbHeight); diff --git a/vnc.html b/vnc.html index 24a118dbd..23d90d207 100644 --- a/vnc.html +++ b/vnc.html @@ -170,6 +170,7 @@

no
VNC

+

  • From ef0d6304f1b1407e16d0e5ed46bdc25617a03a43 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:30:23 +0800 Subject: [PATCH 02/14] Dealing with Lint issues --- app/ui.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/ui.js b/app/ui.js index 062d7d2f6..8ee058a9f 100644 --- a/app/ui.js +++ b/app/ui.js @@ -1352,16 +1352,17 @@ const UI = { UI.enableSetting('view_clip'); UI.rfb.clipViewport = UI.getSetting('view_clip'); } - + // Determines whether it is a window.open window // as window.open(\'/vnc/?token=token&autoconnect=1&resize=browser\',\'_blank\',\'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=800,height=420\'); - var win = window.opener; - if(win == null){ + const win = window.opener; + + if (win == null) { document.getElementById("noVNC_setting_browser_resize").disabled = true; - }else{ + } else { document.getElementById("noVNC_setting_browser_resize").disabled = false; } - + // Changing the viewport may change the state of // the dragging button UI.updateViewDrag(); From 094398037730292679a4351c7cedaa46ebb7e655 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:31:46 +0800 Subject: [PATCH 03/14] Dealing with Lint issues --- core/rfb.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/core/rfb.js b/core/rfb.js index 851769d94..006e4df7f 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -356,7 +356,7 @@ export default class RFB extends EventTargetMixin { get resizeBrowser() { return this._resizeBrowser; } set resizeBrowser(resize) { this._resizeBrowser = resize; - if(this._resizeBrowser && (this._rfbConnectionState === 'connected')){ + if (this._resizeBrowser && (this._rfbConnectionState === 'connected')) { this._updateBrowserWindows(this._fbWidth, this._fbHeight); } } @@ -2873,13 +2873,14 @@ export default class RFB extends EventTargetMixin { } _updateBrowserWindows(width, height) { - if(this._resizeBrowser && (this._rfbConnectionState === 'connected')){ - var fbWidth = width; - var fbHeight = height; - var bodyWidth = document.body.clientWidth; - var bodyHeight = document.body.clientHeight; - if((fbWidth != 0) && (fbHeight != 0)){ - window.resizeBy(fbWidth - bodyWidth,fbHeight - bodyHeight); + if (this._resizeBrowser && + this._rfbConnectionState === 'connected') { + const fbWidth = width; + const fbHeight = height; + const bodyWidth = document.body.clientWidth; + const bodyHeight = document.body.clientHeight; + if ((fbWidth != 0) && (fbHeight != 0)) { + window.resizeBy(fbWidth - bodyWidth, fbHeight - bodyHeight); } } } @@ -2887,7 +2888,7 @@ export default class RFB extends EventTargetMixin { _resize(width, height) { this._fbWidth = width; this._fbHeight = height; - + this._updateBrowserWindows(width, height); this._display.resize(this._fbWidth, this._fbHeight); From 0b6dbd72ab385e77ffe4e165887fafafe694bb81 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:34:35 +0800 Subject: [PATCH 04/14] Dealing with Lint issues --- core/rfb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/rfb.js b/core/rfb.js index 006e4df7f..5e5b55cf1 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -2873,7 +2873,7 @@ export default class RFB extends EventTargetMixin { } _updateBrowserWindows(width, height) { - if (this._resizeBrowser && + if (this._resizeBrowser && this._rfbConnectionState === 'connected') { const fbWidth = width; const fbHeight = height; From e32ad792d1933f5ba7a68ab824831c683b81ed41 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Fri, 16 Aug 2024 23:16:31 +0800 Subject: [PATCH 05/14] Added a condition to change the size --- core/rfb.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/core/rfb.js b/core/rfb.js index 5e5b55cf1..3d0d7020c 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -85,6 +85,10 @@ const extendedClipboardActionPeek = 1 << 26; const extendedClipboardActionNotify = 1 << 27; const extendedClipboardActionProvide = 1 << 28; +// Old browser resolution +let bodyWidth_browser_resize = 0; +let bodyHeight_browser_resize = 0; + export default class RFB extends EventTargetMixin { constructor(target, urlOrChannel, options) { if (!target) { @@ -356,6 +360,9 @@ export default class RFB extends EventTargetMixin { get resizeBrowser() { return this._resizeBrowser; } set resizeBrowser(resize) { this._resizeBrowser = resize; + if (this._resizeBrowser) { + bodyHeight_browser_resize = 0; + } if (this._resizeBrowser && (this._rfbConnectionState === 'connected')) { this._updateBrowserWindows(this._fbWidth, this._fbHeight); } @@ -2873,14 +2880,25 @@ export default class RFB extends EventTargetMixin { } _updateBrowserWindows(width, height) { - if (this._resizeBrowser && + if (this._resizeBrowser && this._rfbConnectionState === 'connected') { const fbWidth = width; const fbHeight = height; - const bodyWidth = document.body.clientWidth; - const bodyHeight = document.body.clientHeight; - if ((fbWidth != 0) && (fbHeight != 0)) { - window.resizeBy(fbWidth - bodyWidth, fbHeight - bodyHeight); + let OldResolutionEqual = false; + + if (bodyWidth_browser_resize === document.body.clientWidth && + bodyHeight_browser_resize === document.body.clientHeight) { + OldResolutionEqual = true; + } + if (bodyHeight_browser_resize === 0 || + OldResolutionEqual) { + bodyWidth_browser_resize = document.body.clientWidth; + bodyHeight_browser_resize = document.body.clientHeight; + if ((fbWidth != 0) && (fbHeight != 0)) { + window.resizeBy(fbWidth - bodyWidth_browser_resize, fbHeight - bodyHeight_browser_resize); + } + } else { + this._resizeBrowser = false; } } } From e4f1779692d59800ba2991f1d20f7ad1360dee54 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Fri, 16 Aug 2024 23:21:26 +0800 Subject: [PATCH 06/14] Dealing with Lint issues --- core/rfb.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/rfb.js b/core/rfb.js index 3d0d7020c..9deb87d24 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -86,8 +86,8 @@ const extendedClipboardActionNotify = 1 << 27; const extendedClipboardActionProvide = 1 << 28; // Old browser resolution -let bodyWidth_browser_resize = 0; -let bodyHeight_browser_resize = 0; +let bodyWidthBrowserResize = 0; +let bodyHeightBrowserResize = 0; export default class RFB extends EventTargetMixin { constructor(target, urlOrChannel, options) { @@ -361,7 +361,7 @@ export default class RFB extends EventTargetMixin { set resizeBrowser(resize) { this._resizeBrowser = resize; if (this._resizeBrowser) { - bodyHeight_browser_resize = 0; + bodyHeightBrowserResize = 0; } if (this._resizeBrowser && (this._rfbConnectionState === 'connected')) { this._updateBrowserWindows(this._fbWidth, this._fbHeight); @@ -2886,16 +2886,16 @@ export default class RFB extends EventTargetMixin { const fbHeight = height; let OldResolutionEqual = false; - if (bodyWidth_browser_resize === document.body.clientWidth && - bodyHeight_browser_resize === document.body.clientHeight) { + if (bodyWidthBrowserResize === document.body.clientWidth && + bodyHeightBrowserResize === document.body.clientHeight) { OldResolutionEqual = true; } - if (bodyHeight_browser_resize === 0 || + if (bodyHeightBrowserResize === 0 || OldResolutionEqual) { - bodyWidth_browser_resize = document.body.clientWidth; - bodyHeight_browser_resize = document.body.clientHeight; + bodyWidthBrowserResize = document.body.clientWidth; + bodyHeightBrowserResize = document.body.clientHeight; if ((fbWidth != 0) && (fbHeight != 0)) { - window.resizeBy(fbWidth - bodyWidth_browser_resize, fbHeight - bodyHeight_browser_resize); + window.resizeBy(fbWidth - bodyWidthBrowserResize, fbHeight - bodyHeightBrowserResize); } } else { this._resizeBrowser = false; From d98ca43d68940b553eb321240002ab0605437a0f Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Fri, 16 Aug 2024 23:23:35 +0800 Subject: [PATCH 07/14] Dealing with Lint issues --- core/rfb.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/rfb.js b/core/rfb.js index 9deb87d24..9f4f35a54 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -2880,7 +2880,7 @@ export default class RFB extends EventTargetMixin { } _updateBrowserWindows(width, height) { - if (this._resizeBrowser && + if (this._resizeBrowser && this._rfbConnectionState === 'connected') { const fbWidth = width; const fbHeight = height; @@ -2888,15 +2888,15 @@ export default class RFB extends EventTargetMixin { if (bodyWidthBrowserResize === document.body.clientWidth && bodyHeightBrowserResize === document.body.clientHeight) { - OldResolutionEqual = true; + OldResolutionEqual = true; } if (bodyHeightBrowserResize === 0 || OldResolutionEqual) { - bodyWidthBrowserResize = document.body.clientWidth; - bodyHeightBrowserResize = document.body.clientHeight; - if ((fbWidth != 0) && (fbHeight != 0)) { - window.resizeBy(fbWidth - bodyWidthBrowserResize, fbHeight - bodyHeightBrowserResize); - } + bodyWidthBrowserResize = document.body.clientWidth; + bodyHeightBrowserResize = document.body.clientHeight; + if ((fbWidth != 0) && (fbHeight != 0)) { + window.resizeBy(fbWidth - bodyWidthBrowserResize, fbHeight - bodyHeightBrowserResize); + } } else { this._resizeBrowser = false; } From 4f839a297eeb9c7a88fc1d9ce3c767cc2afd77f7 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Sat, 17 Aug 2024 00:06:16 +0800 Subject: [PATCH 08/14] Update API.md --- docs/API.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/API.md b/docs/API.md index eb3ec333b..1cf4a6638 100644 --- a/docs/API.md +++ b/docs/API.md @@ -71,6 +71,12 @@ protocol stream. should be sent whenever the container changes dimensions. Disabled by default. +`resizeBrowser` + - Is a `boolean` Indicates whether the browser window was requested to + be resized. should be sent whenever the container changes dimensions. + Manually changing the browser size once enabled will cause it to + Disabled . Disabled by default. + `scaleViewport` - Is a `boolean` indicating if the remote session should be scaled locally so it fits its container. When disabled it will be centered From 2c343a64ea753f1364734e0f9f4afc73c5ab357e Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Sat, 17 Aug 2024 00:20:45 +0800 Subject: [PATCH 09/14] Update API.md --- docs/API.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/API.md b/docs/API.md index 1cf4a6638..1d92b2870 100644 --- a/docs/API.md +++ b/docs/API.md @@ -72,8 +72,8 @@ protocol stream. by default. `resizeBrowser` - - Is a `boolean` Indicates whether the browser window was requested to - be resized. should be sent whenever the container changes dimensions. + - Is a `boolean` indicating if a request to resize the container + should be sent whenever the remote session changes dimensions. Manually changing the browser size once enabled will cause it to Disabled . Disabled by default. From ae7508985b16ff25113c119b8b95f4f28ad0f6f0 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Sat, 17 Aug 2024 00:23:20 +0800 Subject: [PATCH 10/14] Update EMBEDDING.md --- docs/EMBEDDING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/EMBEDDING.md b/docs/EMBEDDING.md index 105001410..dc976ccfc 100644 --- a/docs/EMBEDDING.md +++ b/docs/EMBEDDING.md @@ -59,7 +59,7 @@ query string. Currently the following options are available: it cannot fit in the browser. * `resize` - How to resize the remote session if it is not the same size as - the browser window. Can be one of `off`, `scale` and `remote`. + the browser window. Can be one of `off`, `browser`, `scale` and `remote`. * `quality` - The session JPEG quality level. Can be `0` to `9`. From 7da9506e453e66eb06151ed49217fe6517e06e61 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Sat, 17 Aug 2024 00:48:11 +0800 Subject: [PATCH 11/14] Update API.md --- docs/API.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/API.md b/docs/API.md index 1d92b2870..cabd0c2a3 100644 --- a/docs/API.md +++ b/docs/API.md @@ -76,6 +76,19 @@ protocol stream. should be sent whenever the remote session changes dimensions. Manually changing the browser size once enabled will cause it to Disabled . Disabled by default. + + **For security reasons, it's no longer possible in Firefox for + a website to change the default size of a window in a browser + if the window wasn't created by , or contains more than one tab. + See the compatibility table for details on the change. window.open()** + + **Even if you create window by it is not resizable by default. + To make the window resizable, you must open it with the feature. + window.open()"`resizable`"** + +```js +window.open('vnc.html/token=token&autoconnect=1&resize=browser','_blank','toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=800,height=420'); +``` `scaleViewport` - Is a `boolean` indicating if the remote session should be scaled From 303e5abeaf2d3d600969bb6ffcd35e32dde983c5 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Sat, 17 Aug 2024 00:49:51 +0800 Subject: [PATCH 12/14] Update API.md --- docs/API.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/API.md b/docs/API.md index cabd0c2a3..de87e947d 100644 --- a/docs/API.md +++ b/docs/API.md @@ -77,6 +77,8 @@ protocol stream. Manually changing the browser size once enabled will cause it to Disabled . Disabled by default. + **warn** + **For security reasons, it's no longer possible in Firefox for a website to change the default size of a window in a browser if the window wasn't created by , or contains more than one tab. From feb0c9c09b6119e8dc80d11a25182afcb7d1efe5 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Sat, 17 Aug 2024 01:16:35 +0800 Subject: [PATCH 13/14] Update EMBEDDING.md --- docs/EMBEDDING.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/EMBEDDING.md b/docs/EMBEDDING.md index dc976ccfc..e86c5415e 100644 --- a/docs/EMBEDDING.md +++ b/docs/EMBEDDING.md @@ -59,7 +59,7 @@ query string. Currently the following options are available: it cannot fit in the browser. * `resize` - How to resize the remote session if it is not the same size as - the browser window. Can be one of `off`, `browser`, `scale` and `remote`. + the browser window. Can be one of `off`, [`browser`](#resizebrowser), `scale` and `remote`. * `quality` - The session JPEG quality level. Can be `0` to `9`. @@ -103,3 +103,28 @@ Nginx: # In the location block related to noVNC add_header Cache-Control no-cache; ``` + +### resize:browser + + For security reasons, it's no longer possible in Firefox for + a website to change the default size of a window in a browser + if the window wasn't created by , or contains more than one tab. + See the compatibility table for details on the change. window.open() + + Even if you create window by it is not resizable by default. + To make the window resizable, you must open it with the feature. + window.open()"`resizable`" + +```js +window.open('vnc.html/token=token&autoconnect=1&resize=browser','_blank','toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=800,height=420'); +``` + +#### Browser compatibility + + | browser | version | resize:browser + | ------------ | ---- | ----------- + | `Chrome` | 1 | `window.open(rul,,"_blank","resizable=yes")` + | `Edge` | 12 | `window.open(rul,,"_blank","resizable=yes")` + | `Firefox` | 1 | `window.open(rul,,"_blank","resizable=yes")` + | `Opera` | 12.1 | `window.open(rul,,"_blank","resizable=yes")` + | `Safari` | 1 | `window.open(rul,,"_blank","resizable=yes")` From 4e06e277c3e1bef229c2db3d1949371823a0d893 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <76765956+XiaoXianNv-boot@users.noreply.github.com> Date: Sat, 17 Aug 2024 01:19:53 +0800 Subject: [PATCH 14/14] Update API.md --- docs/API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/API.md b/docs/API.md index de87e947d..04a40873b 100644 --- a/docs/API.md +++ b/docs/API.md @@ -82,7 +82,7 @@ protocol stream. **For security reasons, it's no longer possible in Firefox for a website to change the default size of a window in a browser if the window wasn't created by , or contains more than one tab. - See the compatibility table for details on the change. window.open()** + [See the compatibility table for details on the change.](EMBEDDING.md#browser-compatibility) window.open()** **Even if you create window by it is not resizable by default. To make the window resizable, you must open it with the feature.