@sparkvault/sdk-js 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -39,9 +39,22 @@ export declare class WidgetEmbedder {
|
|
|
39
39
|
private previousBodyOverflow;
|
|
40
40
|
private readonly trustedOrigin;
|
|
41
41
|
private readonly boundHandleMessage;
|
|
42
|
+
private readonly boundHandleCspViolation;
|
|
42
43
|
constructor(config: ResolvedConfig, options: VerifyOptions, callbacks: EmbedderCallbacks);
|
|
43
44
|
start(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Nudge the browser to paint the just-inserted iframe on the next frame.
|
|
47
|
+
* Reading layout forces a reflow; toggling a transform forces the compositor
|
|
48
|
+
* to flush the new layer — the workaround for iOS Safari leaving a fixed
|
|
49
|
+
* full-viewport iframe invisible until an unrelated repaint.
|
|
50
|
+
*/
|
|
51
|
+
private forceComposite;
|
|
44
52
|
close(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Host CSP blocked the widget iframe (frame-src/child-src). The frame can
|
|
55
|
+
* never load, so fail over to the in-page flow immediately.
|
|
56
|
+
*/
|
|
57
|
+
private handleCspViolation;
|
|
45
58
|
private clearReadyTimer;
|
|
46
59
|
/**
|
|
47
60
|
* The widget frame never became interactive. Tear down, release the host
|
package/dist/sparkvault.cjs.js
CHANGED
|
@@ -6897,7 +6897,7 @@ class IdentityRenderer {
|
|
|
6897
6897
|
}
|
|
6898
6898
|
}
|
|
6899
6899
|
|
|
6900
|
-
/* global HTMLIFrameElement */
|
|
6900
|
+
/* global HTMLIFrameElement requestAnimationFrame */
|
|
6901
6901
|
/**
|
|
6902
6902
|
* Widget Embedder
|
|
6903
6903
|
*
|
|
@@ -6945,6 +6945,7 @@ class WidgetEmbedder {
|
|
|
6945
6945
|
// against — never the broader sparkvault.com family.
|
|
6946
6946
|
this.trustedOrigin = new URL(this.config.identityBaseUrl).origin;
|
|
6947
6947
|
this.boundHandleMessage = (event) => this.handleMessage(event);
|
|
6948
|
+
this.boundHandleCspViolation = (event) => this.handleCspViolation(event);
|
|
6948
6949
|
}
|
|
6949
6950
|
start() {
|
|
6950
6951
|
const iframe = document.createElement('iframe');
|
|
@@ -6964,6 +6965,12 @@ class WidgetEmbedder {
|
|
|
6964
6965
|
'background:transparent',
|
|
6965
6966
|
'z-index:2147483647',
|
|
6966
6967
|
].join(';');
|
|
6968
|
+
// Promote to its own compositing layer up front. iOS Safari can otherwise
|
|
6969
|
+
// leave a freshly-inserted fixed, full-viewport iframe loaded but UNPAINTED
|
|
6970
|
+
// until the next composite (a scroll, resize, or app foreground) — the
|
|
6971
|
+
// frame even runs, but the dialog only appears after an app switch.
|
|
6972
|
+
iframe.style.transform = 'translateZ(0)';
|
|
6973
|
+
iframe.style.willChange = 'transform';
|
|
6967
6974
|
// A network-level load failure (DNS, connection reset) fires onerror; an
|
|
6968
6975
|
// HTTP error body or a frame blocked from framing does not, which is what
|
|
6969
6976
|
// the readiness timeout below covers.
|
|
@@ -6973,9 +6980,36 @@ class WidgetEmbedder {
|
|
|
6973
6980
|
this.previousBodyOverflow = document.body.style.overflow;
|
|
6974
6981
|
document.body.style.overflow = 'hidden';
|
|
6975
6982
|
window.addEventListener('message', this.boundHandleMessage);
|
|
6983
|
+
// A host-page CSP whose frame-src/child-src omits the Identity origin blocks
|
|
6984
|
+
// the iframe before it can load and fires no `onerror`. Catch the violation
|
|
6985
|
+
// so we fail over to the in-page flow at once instead of after the timeout.
|
|
6986
|
+
document.addEventListener('securitypolicyviolation', this.boundHandleCspViolation);
|
|
6976
6987
|
document.body.appendChild(iframe);
|
|
6988
|
+
// Force the composite the iframe insertion may not have triggered on iOS,
|
|
6989
|
+
// so the dialog paints on the click rather than only after an app switch.
|
|
6990
|
+
this.forceComposite(iframe);
|
|
6977
6991
|
this.readyTimer = setTimeout(() => this.handleFrameUnavailable(), FRAME_READY_TIMEOUT_MS);
|
|
6978
6992
|
}
|
|
6993
|
+
/**
|
|
6994
|
+
* Nudge the browser to paint the just-inserted iframe on the next frame.
|
|
6995
|
+
* Reading layout forces a reflow; toggling a transform forces the compositor
|
|
6996
|
+
* to flush the new layer — the workaround for iOS Safari leaving a fixed
|
|
6997
|
+
* full-viewport iframe invisible until an unrelated repaint.
|
|
6998
|
+
*/
|
|
6999
|
+
forceComposite(iframe) {
|
|
7000
|
+
const paint = () => {
|
|
7001
|
+
if (!this.iframe)
|
|
7002
|
+
return;
|
|
7003
|
+
void iframe.offsetHeight;
|
|
7004
|
+
iframe.style.transform = 'translateZ(0) scale(1)';
|
|
7005
|
+
};
|
|
7006
|
+
if (typeof requestAnimationFrame === 'function') {
|
|
7007
|
+
requestAnimationFrame(paint);
|
|
7008
|
+
}
|
|
7009
|
+
else {
|
|
7010
|
+
setTimeout(paint, 16);
|
|
7011
|
+
}
|
|
7012
|
+
}
|
|
6979
7013
|
close() {
|
|
6980
7014
|
this.clearReadyTimer();
|
|
6981
7015
|
if (this.iframe?.parentNode) {
|
|
@@ -6983,8 +7017,22 @@ class WidgetEmbedder {
|
|
|
6983
7017
|
}
|
|
6984
7018
|
this.iframe = null;
|
|
6985
7019
|
window.removeEventListener('message', this.boundHandleMessage);
|
|
7020
|
+
document.removeEventListener('securitypolicyviolation', this.boundHandleCspViolation);
|
|
6986
7021
|
document.body.style.overflow = this.previousBodyOverflow;
|
|
6987
7022
|
}
|
|
7023
|
+
/**
|
|
7024
|
+
* Host CSP blocked the widget iframe (frame-src/child-src). The frame can
|
|
7025
|
+
* never load, so fail over to the in-page flow immediately.
|
|
7026
|
+
*/
|
|
7027
|
+
handleCspViolation(event) {
|
|
7028
|
+
const directive = event.effectiveDirective || event.violatedDirective;
|
|
7029
|
+
if (directive !== 'frame-src' && directive !== 'child-src')
|
|
7030
|
+
return;
|
|
7031
|
+
// blockedURI is the framed URL (sometimes just its origin); match either.
|
|
7032
|
+
if (typeof event.blockedURI === 'string' && event.blockedURI.startsWith(this.trustedOrigin)) {
|
|
7033
|
+
this.handleFrameUnavailable();
|
|
7034
|
+
}
|
|
7035
|
+
}
|
|
6988
7036
|
clearReadyTimer() {
|
|
6989
7037
|
if (this.readyTimer !== null) {
|
|
6990
7038
|
clearTimeout(this.readyTimer);
|