5180 fichiers 38.5 Mo 0 téléchargements 195 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / api / utils / resolveAdsFrame.ts
resolveAdsFrame.ts 1.5 Ko Télécharger le fichier
export interface AdsFrame {
    src: string;
    sandbox: string;
}

export interface AdsFrameSlot {
    publisherId: string;
    slot: string;
    format?: string;
    fullWidthResponsive?: boolean;
}

const SANDBOX = 'allow-scripts allow-popups allow-popups-to-escape-sandbox';

/**
 * The frame an ad is shown in when the hotel serves its ad page from another origin (`ads.frame.url`). The ad
 * script then runs there, away from the client's session; the frame may open the advertiser in a new tab but never
 * navigate the client. A page on the client's own origin would share its storage, so it gets no same-origin rights.
 * Returns null when the URL is not a plain web URL.
 */
export const resolveAdsFrame = (frameUrl: string, slot: AdsFrameSlot, clientOrigin: string): AdsFrame | null => {
    if (!frameUrl || typeof frameUrl !== 'string') return null;

    let target: URL;
    try {
        target = new URL(frameUrl.trim(), clientOrigin);
    } catch {
        return null;
    }

    if (target.protocol !== 'https:' && target.protocol !== 'http:') return null;

    target.searchParams.set('client', `ca-${slot.publisherId}`);
    target.searchParams.set('slot', slot.slot);
    target.searchParams.set('format', slot.format ?? 'auto');
    target.searchParams.set('responsive', (slot.fullWidthResponsive ?? true) ? 'true' : 'false');

    const sameOrigin = target.origin === clientOrigin;

    return { src: target.href, sandbox: sameOrigin ? SANDBOX : `${SANDBOX} allow-same-origin` };
};
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser