From f7338f3a04058681780e0bcb9e77d7ba6218590b Mon Sep 17 00:00:00 2001 From: "P. Douglas Reeder" Date: Sat, 28 Sep 2024 18:13:26 -0400 Subject: [PATCH 1/7] Gracefully handles when Document's Permission Policy does not allow calling getGamepads() from the context (such as an IFRAME). --- src/systems/tracked-controls-webvr.js | 36 +++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/systems/tracked-controls-webvr.js b/src/systems/tracked-controls-webvr.js index d30ff98090e..0717ef0b3c6 100644 --- a/src/systems/tracked-controls-webvr.js +++ b/src/systems/tracked-controls-webvr.js @@ -41,26 +41,30 @@ module.exports.System = registerSystem('tracked-controls-webvr', { * Update controller list. */ updateControllerList: function () { - var controllers = this.controllers; - var gamepad; - var gamepads; - var i; - var prevCount; + try { + var controllers = this.controllers; + var gamepad; + var gamepads; + var i; + var prevCount; - gamepads = navigator.getGamepads && navigator.getGamepads(); - if (!gamepads) { return; } + gamepads = navigator.getGamepads && navigator.getGamepads(); + if (!gamepads) { return; } - prevCount = controllers.length; - controllers.length = 0; - for (i = 0; i < gamepads.length; ++i) { - gamepad = gamepads[i]; - if (gamepad && gamepad.pose) { - controllers.push(gamepad); + prevCount = controllers.length; + controllers.length = 0; + for (i = 0; i < gamepads.length; ++i) { + gamepad = gamepads[i]; + if (gamepad && gamepad.pose) { + controllers.push(gamepad); + } } - } - if (controllers.length !== prevCount) { - this.el.emit('controllersupdated', undefined, false); + if (controllers.length !== prevCount) { + this.el.emit('controllersupdated', undefined, false); + } + } catch (e) { + console.warn('can\'t update controller list:', e); } } }); From 07650eeadcef92e8ca49bfa25a9b6cf7a9864341 Mon Sep 17 00:00:00 2001 From: "P. Douglas Reeder" Date: Sat, 28 Sep 2024 21:20:33 -0400 Subject: [PATCH 2/7] Improves warning message --- src/systems/tracked-controls-webvr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/systems/tracked-controls-webvr.js b/src/systems/tracked-controls-webvr.js index 0717ef0b3c6..ab62cc894ff 100644 --- a/src/systems/tracked-controls-webvr.js +++ b/src/systems/tracked-controls-webvr.js @@ -64,7 +64,7 @@ module.exports.System = registerSystem('tracked-controls-webvr', { this.el.emit('controllersupdated', undefined, false); } } catch (e) { - console.warn('can\'t update controller list:', e); + console.warn('A-Frame requires additional permissions to list the gamepads. If this is running in an IFRAME, you need to add `gamepads` to the `allow` attribute. If this is running as the top-level page, the HTTP `Permissions-Policy` header must not exclude this origin in the `gamepad` directive.', e); } } }); From 7a6a13d8658cd6cb14ee3e74eae4b2cc27b3e7ca Mon Sep 17 00:00:00 2001 From: "P. Douglas Reeder" Date: Sun, 29 Sep 2024 22:24:54 -0400 Subject: [PATCH 3/7] tracked-controllers-webvr: separate error messages for permission and coding errors --- src/systems/tracked-controls-webvr.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/systems/tracked-controls-webvr.js b/src/systems/tracked-controls-webvr.js index ab62cc894ff..d104bb3601c 100644 --- a/src/systems/tracked-controls-webvr.js +++ b/src/systems/tracked-controls-webvr.js @@ -64,7 +64,11 @@ module.exports.System = registerSystem('tracked-controls-webvr', { this.el.emit('controllersupdated', undefined, false); } } catch (e) { - console.warn('A-Frame requires additional permissions to list the gamepads. If this is running in an IFRAME, you need to add `gamepads` to the `allow` attribute. If this is running as the top-level page, the HTTP `Permissions-Policy` header must not exclude this origin in the `gamepad` directive.', e); + if (e.name === 'SecurityError') { + console.warn('A-Frame requires additional permissions to list the gamepads. If this is running in an IFRAME, you need to add `gamepads` to the `allow` attribute. If this is running as the top-level page, the HTTP `Permissions-Policy` header must not exclude this origin in the `gamepad` directive.', e); + } else { + console.error('Can\'t update controller list:', e); + } } } }); From 9eaeb0f91788b024a80d6a9b43e6eeef096cea66 Mon Sep 17 00:00:00 2001 From: "P. Douglas Reeder" Date: Mon, 30 Sep 2024 11:31:57 -0400 Subject: [PATCH 4/7] tracked-controls: specific warning messages when gamepad access is blocked --- src/systems/tracked-controls-webvr.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/systems/tracked-controls-webvr.js b/src/systems/tracked-controls-webvr.js index d104bb3601c..646eb2cc50c 100644 --- a/src/systems/tracked-controls-webvr.js +++ b/src/systems/tracked-controls-webvr.js @@ -65,7 +65,11 @@ module.exports.System = registerSystem('tracked-controls-webvr', { } } catch (e) { if (e.name === 'SecurityError') { - console.warn('A-Frame requires additional permissions to list the gamepads. If this is running in an IFRAME, you need to add `gamepads` to the `allow` attribute. If this is running as the top-level page, the HTTP `Permissions-Policy` header must not exclude this origin in the `gamepad` directive.', e); + if (window.self === window.top) { + console.warn('A-Frame requires additional permissions to list the gamepads. The HTTP `Permissions-Policy` header must not exclude this origin in the `gamepad` directive.', e); + } else { + console.warn('A-Frame requires additional permissions to list the gamepads. The iframe `allow` attribute must not block this origin.', e); + } } else { console.error('Can\'t update controller list:', e); } From ab0065fdf7fbbca998f659712b5d8b24c42b3a81 Mon Sep 17 00:00:00 2001 From: "P. Douglas Reeder" Date: Tue, 1 Oct 2024 16:36:43 -0400 Subject: [PATCH 5/7] tracked-controls: updates wording of gamepad error messages --- src/systems/tracked-controls-webvr.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/systems/tracked-controls-webvr.js b/src/systems/tracked-controls-webvr.js index 646eb2cc50c..94e69eb531c 100644 --- a/src/systems/tracked-controls-webvr.js +++ b/src/systems/tracked-controls-webvr.js @@ -66,9 +66,9 @@ module.exports.System = registerSystem('tracked-controls-webvr', { } catch (e) { if (e.name === 'SecurityError') { if (window.self === window.top) { - console.warn('A-Frame requires additional permissions to list the gamepads. The HTTP `Permissions-Policy` header must not exclude this origin in the `gamepad` directive.', e); + console.warn('The HTTP `Permissions-Policy` header must not block this origin in the `gamepad` directive, to allow A-Frame to list the gamepads.', e); } else { - console.warn('A-Frame requires additional permissions to list the gamepads. The iframe `allow` attribute must not block this origin.', e); + console.warn('The iframe `allow` attribute must not block the origin of this A-Frame app, to allow A-Frame to list the gamepads.', e); } } else { console.error('Can\'t update controller list:', e); From 6a6bb020a6fdc2be145fadf5c2478ea14560161f Mon Sep 17 00:00:00 2001 From: "P. Douglas Reeder" Date: Sun, 13 Oct 2024 15:48:31 -0400 Subject: [PATCH 6/7] tracked-controls: only shows permissions warning once --- examples/test/iframe/index.html | 2 +- src/systems/tracked-controls-webvr.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/test/iframe/index.html b/examples/test/iframe/index.html index 30d6b757787..4e554b44afe 100644 --- a/examples/test/iframe/index.html +++ b/examples/test/iframe/index.html @@ -41,7 +41,7 @@ - +