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() { constructor() {
super(); super();
this.debug = false; this.debug = false;
this._initResizeObserver();
this._initTitleMutationObserver();
this._handleWindowMessage = this._handleWindowMessage.bind(this); this._handleWindowMessage = this._handleWindowMessage.bind(this);
this._initObservers = this._initObservers.bind(this);
window.addEventListener("load", this._initObservers);
window.addEventListener("message", this._handleWindowMessage); window.addEventListener("message", this._handleWindowMessage);
} }
post(message, target = window.parent) { post(message, target = window.parent) {
@ -4119,6 +4119,10 @@ var Edge = (() => {
}); });
this.dispatchEvent(event); this.dispatchEvent(event);
} }
_initObservers() {
this._initResizeObserver();
this._initTitleMutationObserver();
}
_initTitleMutationObserver() { _initTitleMutationObserver() {
const titleObserver = new MutationObserver((mutations) => { const titleObserver = new MutationObserver((mutations) => {
const title2 = mutations[0].target.textContent; const title2 = mutations[0].target.textContent;
@ -4132,24 +4136,27 @@ var Edge = (() => {
} }
_initResizeObserver() { _initResizeObserver() {
const resizeObserver = new ResizeObserver(() => { const resizeObserver = new ResizeObserver(() => {
const body = document.body, html = document.documentElement; const body2 = document.body, html = document.documentElement;
const height = Math.max( const height = Math.max(
body.scrollHeight, body2.scrollHeight,
body.offsetHeight, body2.offsetHeight,
html.clientHeight, html.clientHeight,
html.scrollHeight, html.scrollHeight,
html.offsetHeight html.offsetHeight
); );
const width = Math.max( const width = Math.max(
body.scrollWidth, body2.scrollWidth,
body.offsetWidth, body2.offsetWidth,
html.clientWidth, html.clientWidth,
html.scrollWidth, html.scrollWidth,
html.offsetWidth html.offsetWidth
); );
this.post({ type: "size_changed" /* SIZE_CHANGED */, data: { height, width } }); 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() super()
this.debug = false; this.debug = false;
this._initResizeObserver();
this._initTitleMutationObserver();
this._handleWindowMessage = this._handleWindowMessage.bind(this); this._handleWindowMessage = this._handleWindowMessage.bind(this);
this._initObservers = this._initObservers.bind(this);
window.addEventListener('load', this._initObservers);
window.addEventListener('message', this._handleWindowMessage) window.addEventListener('message', this._handleWindowMessage)
} }
@ -46,6 +45,11 @@ export class CrossFrameMessenger extends EventTarget {
this.dispatchEvent(event); this.dispatchEvent(event);
} }
_initObservers() {
this._initResizeObserver();
this._initTitleMutationObserver();
}
_initTitleMutationObserver() { _initTitleMutationObserver() {
const titleObserver = new MutationObserver((mutations) => { const titleObserver = new MutationObserver((mutations) => {
const title = mutations[0].target.textContent; const title = mutations[0].target.textContent;
@ -75,6 +79,10 @@ export class CrossFrameMessenger extends EventTarget {
this.post({ type: CrossFrameMessageType.SIZE_CHANGED, data: { height, width }}); this.post({ type: CrossFrameMessageType.SIZE_CHANGED, data: { height, width }});
}); });
resizeObserver.observe(document.body); const body = document.body;
if (!body) return;
resizeObserver.observe(body);
} }
} }