From 2b4b17f42ad239b61c14a5093ff8cd17c259f27c Mon Sep 17 00:00:00 2001 From: Aram Grigoryan <132480+aram356@users.noreply.github.com> Date: Fri, 31 Jul 2026 14:09:11 -0700 Subject: [PATCH] Load the decoupled prebid shim in the APS renderer browser spec The APS adapter spec loads the external Prebid bundle and assumed it carries the tsjs shim (and the trustedServer adapter) inside it. Once the shim is decoupled (PR #967) the external bundle is pure Prebid.js, no adapter ever registers, and the in-page auction times out. Detect the decoupled world through the window.__tsjs_prebid_bundle manifest stamp and load dist/tsjs-prebid.js after the external bundle, matching the script order the server actually serves. On a coupled bundle the stamp is absent and the spec behaves exactly as before. --- .../browser/tests/shared/aps-renderer.spec.ts | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/crates/trusted-server-integration-tests/browser/tests/shared/aps-renderer.spec.ts b/crates/trusted-server-integration-tests/browser/tests/shared/aps-renderer.spec.ts index 84d6d49e3..6c0301e2c 100644 --- a/crates/trusted-server-integration-tests/browser/tests/shared/aps-renderer.spec.ts +++ b/crates/trusted-server-integration-tests/browser/tests/shared/aps-renderer.spec.ts @@ -1,6 +1,6 @@ import { readFileSync } from "node:fs"; import { resolve } from "node:path"; -import { expect, test } from "@playwright/test"; +import { expect, test, type Page } from "@playwright/test"; import { runtimeUrl } from "../../helpers/state.js"; const RUNNER_URL = "https://client.aps.amazon-adsystem.com/prebid-creative.js"; @@ -23,6 +23,31 @@ function clientAuctionBundlePaths() { }; } +/** + * Load the client auction scripts in the order the server serves them. + * + * A coupled external bundle ships Prebid.js with the tsjs shim (and the + * trustedServer adapter) already installed. A decoupled external bundle is + * pure Prebid.js and stamps its manifest on `window.__tsjs_prebid_bundle`; + * the shim then arrives as the separately served deferred tsjs module, so + * this helper loads it whenever the stamp is present. + */ +async function loadClientAuctionBundles(page: Page): Promise { + const bundles = clientAuctionBundlePaths(); + await page.addScriptTag({ path: bundles.core }); + await page.addScriptTag({ path: bundles.gpt }); + await page.addScriptTag({ path: bundles.prebid }); + const decoupledBundle = await page.evaluate(() => + Boolean( + (window as unknown as { __tsjs_prebid_bundle?: unknown }) + .__tsjs_prebid_bundle, + ), + ); + if (decoupledBundle) { + await page.addScriptTag({ path: bundles.prebidShim }); + } +} + function descriptor( tagType: "iframe" | "script", creativeUrl = tagType === "iframe" @@ -212,11 +237,7 @@ test.describe("APS opaque renderer", () => { }); await page.goto(runtimeUrl("/aps-prebid-adapter-test")); - const bundles = clientAuctionBundlePaths(); - await page.addScriptTag({ path: bundles.core }); - await page.addScriptTag({ path: bundles.gpt }); - await page.addScriptTag({ path: bundles.prebid }); - await page.addScriptTag({ path: bundles.prebidShim }); + await loadClientAuctionBundles(page); const result = await page.evaluate(async () => { type PrebidBid = {