fix(sdk,client): initialize crossframe observers after window load event
arcad/edge/pipeline/head This commit looks good Details

This commit is contained in:
wpetit 2023-04-06 19:18:36 +02:00
parent 55d7241d95
commit da73b842e1
3 changed files with 30 additions and 15 deletions

View File

@ -4095,9 +4095,9 @@ var Edge = (() => {
constructor() {
super();
this.debug = false;
this._initResizeObserver();
this._initTitleMutationObserver();
this._handleWindowMessage = this._handleWindowMessage.bind(this);
this._initObservers = this._initObservers.bind(this);
window.addEventListener("load", this._initObservers);
window.addEventListener("message", this._handleWindowMessage);
}
post(message, target = window.parent) {
@ -4119,6 +4119,10 @@ var Edge = (() => {
});
this.dispatchEvent(event);
}
_initObservers() {
this._initResizeObserver();
this._initTitleMutationObserver();
}
_initTitleMutationObserver() {
const titleObserver = new MutationObserver((mutations) => {
const title2 = mutations[0].target.textContent;
@ -4132,24 +4136,27 @@ var Edge = (() => {
}
_initResizeObserver() {
const resizeObserver = new ResizeObserver(() => {
const body = document.body, html = document.documentElement;
const body2 = document.body, html = document.documentElement;
const height = Math.max(
body.scrollHeight,
body.offsetHeight,
body2.scrollHeight,
body2.offsetHeight,
html.clientHeight,
html.scrollHeight,
html.offsetHeight
);
const width = Math.max(
body.scrollWidth,
body.offsetWidth,
body2.scrollWidth,
body2.offsetWidth,
html.clientWidth,
html.scrollWidth,
html.offsetWidth
);
this.post({ type: "size_changed" /* SIZE_CHANGED */, data: { height, width } });
});
resizeObserver.observe(document.body);
const body = document.body;
if (!body)
return;
resizeObserver.observe(body);
}
};

File diff suppressed because one or more lines are too long

View File

@ -17,11 +17,10 @@ export class CrossFrameMessenger extends EventTarget {
super()
this.debug = false;
this._initResizeObserver();
this._initTitleMutationObserver();
this._handleWindowMessage = this._handleWindowMessage.bind(this);
this._initObservers = this._initObservers.bind(this);
window.addEventListener('load', this._initObservers);
window.addEventListener('message', this._handleWindowMessage)
}
@ -46,6 +45,11 @@ export class CrossFrameMessenger extends EventTarget {
this.dispatchEvent(event);
}
_initObservers() {
this._initResizeObserver();
this._initTitleMutationObserver();
}
_initTitleMutationObserver() {
const titleObserver = new MutationObserver((mutations) => {
const title = mutations[0].target.textContent;
@ -75,6 +79,10 @@ export class CrossFrameMessenger extends EventTarget {
this.post({ type: CrossFrameMessageType.SIZE_CHANGED, data: { height, width }});
});
resizeObserver.observe(document.body);
const body = document.body;
if (!body) return;
resizeObserver.observe(body);
}
}