-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR implements support for opening immersive experiences directly as soon as the application is launched. We do this by adding a built-in extension which will activate a particular element in the page. We need to set the preference dom.vr.require-gesture to false so this script can launch immersive WebXR experiences. The information required to identify the element to activate is passed as parameters to the Intent: - open_in_immersive - open_in_immersive_parent_xpath - open_in_immersive_element_xpath - a target URL to open
- Loading branch information
1 parent
fb44edc
commit 9f956d4
Showing
5 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
app/src/main/assets/extensions/wolvic_autowebxr/content.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const LOGTAG = '[wolvic:autowebxr]'; | ||
const ENABLE_LOGS = true; | ||
const logDebug = (...args) => ENABLE_LOGS && console.log(LOGTAG, ...args); | ||
|
||
const PARENT_ELEMENT_XPATH_PARAMETER = 'wolvic-autowebxr-parentElementXPath'; | ||
const TARGET_ELEMENT_XPATH_PARAMETER = 'wolvic-autowebxr-targetElementXPath'; | ||
|
||
var parentElementXPath; | ||
var targetElementXPath; | ||
|
||
function getElementByXPath(document, xpath) { | ||
let result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); | ||
return result.singleNodeValue; | ||
} | ||
|
||
function clickImmersiveElement() { | ||
// check if the current URL has extra query parameters | ||
parentElementXPath = undefined; | ||
targetElementXPath = undefined; | ||
|
||
let url = document.URL; | ||
let params = new URLSearchParams(new URL(url).search); | ||
for (let [key, value] of params) { | ||
if (key === 'wolvic-autowebxr-parentElementXPath') | ||
parentElementXPath = value | ||
else if (key === 'wolvic-autowebxr-targetElementXPath') | ||
targetElementXPath = value; | ||
} | ||
|
||
// we need at least the target element to click | ||
if (!targetElementXPath) | ||
return; | ||
|
||
logDebug('Preparing to open immersive WebXR; parentElementXPath: ' + parentElementXPath + ' ; targetElementXPath: ' + targetElementXPath); | ||
|
||
// the parent element is usually an iframe; if parentElementXPath is null, we use the root | ||
|
||
var parent, parentDocument; | ||
if (parentElementXPath) { | ||
var parent = getElementByXPath(document, parentElementXPath); | ||
if (!parent) { | ||
logDebug('parent not found, retrying'); | ||
setTimeout(clickImmersiveElement, 1000); | ||
return; | ||
} | ||
parentDocument = parent.contentDocument || parent.contentWindow.document; | ||
} else { | ||
parent = window; | ||
parentDocument = document; | ||
} | ||
|
||
if (parentDocument.readyState !== 'complete') { | ||
logDebug('parent is still loading'); | ||
parent.addEventListener('load', function() { | ||
logDebug('parent has finished loading'); | ||
clickImmersiveElement(); | ||
}); | ||
return; | ||
} | ||
|
||
logDebug('parent is loaded'); | ||
|
||
let targetElement = getElementByXPath(parentDocument, targetElementXPath); | ||
|
||
if (targetElement) { | ||
logDebug('target element found, clicking'); | ||
// This fails with "DOMException: A user gesture is required" unless dom.vr.require-gesture is set to false. | ||
targetElement.click(); | ||
} else { | ||
logDebug('target element not found, retrying'); | ||
setTimeout(clickImmersiveElement, 1000); | ||
} | ||
} | ||
|
||
if (document.readyState === 'complete') { | ||
logDebug('document is completely ready'); | ||
clickImmersiveElement(); | ||
} else { | ||
logDebug('document is not ready yet'); | ||
window.addEventListener('load', clickImmersiveElement); | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/assets/extensions/wolvic_autowebxr/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"manifest_version": 2, | ||
"name": "Wolvic WebXR Automator", | ||
"version": "1.0", | ||
"description": "Enter WebXR Experiences Automatically", | ||
"browser_specific_settings": { | ||
"gecko": { | ||
"id": "wolvic-autowebxr@igalia.com" | ||
} | ||
}, | ||
"content_scripts": [ | ||
{ | ||
"matches": [ | ||
"*://*/*" | ||
], | ||
"js": [ | ||
"content.js" | ||
], | ||
"run_at": "document_idle", | ||
"all_frames": false | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters