Skip to content

Commit 322280c

Browse files
committed
fix(uiframe): delay shadow DOM creation close #2253
The Amazon Prime Gaming page was failing to load when SurfingKeys was enabled due to premature shadow DOM initialization. his patch delays the creation of the shadow root until the DOM is ready, ensuring that the page loads correctly. Note that while this fixes the loading problem, some commands (e.g., scrolling) still do not work.
1 parent 67f32b2 commit 322280c

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

src/content_scripts/uiframe.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,35 @@ function createUiHost(browser, onload) {
2222
ifr.style.width = "100%";
2323
ifr.style.height = 0;
2424
ifr.style.zIndex = 2147483647;
25-
uiHost.attachShadow({ mode: 'open' });
26-
uiHost.shadowRoot.appendChild(ifr);
25+
26+
// top -> frontend: origin
27+
// frontend -> top:
28+
// top -> top: apply user settings
29+
ifr.addEventListener("load", function() {
30+
this.contentWindow.postMessage({surfingkeys_frontend_data: {
31+
action: 'initFrontend',
32+
ack: true,
33+
winSize: [window.innerWidth, window.innerHeight],
34+
origin: getDocumentOrigin()
35+
}}, frontEndURL);
36+
37+
window.addEventListener('message', _onWindowMessage, true);
38+
}, {once: true});
39+
40+
const createShadowRoot = () => {
41+
uiHost.attachShadow({ mode: 'open' });
42+
uiHost.shadowRoot.appendChild(ifr);
43+
};
44+
45+
if (document.readyState === 'loading') {
46+
// There's no race condition here
47+
// https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event#checking_whether_loading_is_already_complete
48+
document.addEventListener('DOMContentLoaded', () => {
49+
createShadowRoot();
50+
});
51+
} else {
52+
createShadowRoot();
53+
}
2754

2855
function _onWindowMessage(event) {
2956
var _message = event.data && event.data.surfingkeys_uihost_data;
@@ -67,21 +94,6 @@ function createUiHost(browser, onload) {
6794
event.stopImmediatePropagation();
6895
}
6996

70-
// top -> frontend: origin
71-
// frontend -> top:
72-
// top -> top: apply user settings
73-
ifr.addEventListener("load", function() {
74-
this.contentWindow.postMessage({surfingkeys_frontend_data: {
75-
action: 'initFrontend',
76-
ack: true,
77-
winSize: [window.innerWidth, window.innerHeight],
78-
origin: getDocumentOrigin()
79-
}}, frontEndURL);
80-
81-
window.addEventListener('message', _onWindowMessage, true);
82-
83-
}, {once: true});
84-
8597
var lastStateOfPointerEvents = "none", _origOverflowY;
8698
var _actions = {}, activeContent = null;
8799
_actions['initFrontendAck'] = function(response) {

0 commit comments

Comments
 (0)