Prebid.js icon indicating copy to clipboard operation
Prebid.js copied to clipboard

bidWon vs slotRenderEnded order differs on Android Chrome vs Safari (targeting cleared after #15398)

Open bozghiyy opened this issue 1 month ago • 4 comments

Type of issue

Question / discussion (possible cross-browser inconsistency affecting Prebid.js users)

Description

This might not be Prebid.js-specific, but it can impact Prebid.js users.

The ordering of GAM and Prebid events seems different on Android vs iOS.

  • Android: Chrome emulator
  • iOS: Safari on iOS 27 (new enough that I think this is worth flagging)

My guess is Chrome on Android uses scheduler.yield, and Safari does not. If bidWon from Prebid and slotRenderEnded from GAM are queued around the same render path, the order those callbacks run can diverge by browser.

Observed order

Android (Chrome): slotRenderEnded first, then bidWon

https://img.adops.ro/2026-10-16_15-46-31_0efa8866-fc33-4f59-9670-39f6d567b64c.jpg

Safari (iOS): bidWon first, then slotRenderEnded

https://img.adops.ro/2026-10-16_15-47-50_481c21db-d041-4748-903f-7b024c7a223b.jpg

Why this matters more after #15398

Prebid and GAM are different things, so event ordering alone might not have been a huge deal historically. After https://github.com/prebid/Prebid.js/pull/15398 (clear targeting on bidWon), it does make a difference whether bidWon runs before or after slotRenderEnded.

If you listen to slotRenderEnded and read slot.getTargetingMap() for things like bid CPM or post-render checks after the creative has rendered, on Safari the targeting map is already cleared. On Android Chrome those hb_* keys are still there at slotRenderEnded, because bidWon has not run yet.

I am not saying the keys should or should not still be there. Working differently on iOS and Android is the issue.

Of course there are alternatives, like not basing stuff on the GAM event. But let's be honest: slotRenderEnded is the most used GAM event, and developers use it.

Comparison without the bidWon targeting clear (Prebid 11.35.0, pre-#15398)

On the same test page I also included Prebid 11.35.0 (before PR #15398). There we do not clear hb_* on bidWon, and we get a different result:

https://img.adops.ro/2026-10-16_15-53-51_aead13ca-d1aa-4160-b686-e65c13629a62.jpg

Repro

Test page (switch between Prebid 11.35.0 and 11.41.0; mocked bids via the debugging module):

https://stage.adops.ro/pbjs-issue/

Related (not duplicates)

  • #14943 / #15398 — clear/reset GPT targeting on bidWon (this is what surfaces the Safari vs Android difference)
  • #5242 — older discussion of slotRenderEnded vs bidWon timing
  • #10062 — scheduler.yield / main-thread yielding (possible mechanism on the Chrome path)

I could not find an existing issue specifically about Android Chrome vs Safari ordering of bidWon vs slotRenderEnded after targeting reset.

Question

I do not know if there is a fix, or if Prebid should do anything about this. I am looking more for an opinion: should Prebid look into this, or should each integrator take care of what they are building?

bozghiyy avatar Oct 16 '26 13:10 bozghiyy

This is very interesting

You may want to examine https://github.com/prebid/Prebid.js/security/quality/rules/js%2Funhandled-error-in-stream-pipeline

patmmccann avatar Oct 16 '26 16:10 patmmccann

If you listen to slotRenderEnded and read slot.getTargetingMap() for things like bid CPM or post-render checks

what else are you looking at getTargetingMap for? It seems there should usually be a better way.

how about we clear after both events have fired so the order doesnt matter?

patmmccann avatar Oct 19 '26 15:10 patmmccann

of note: we've observed some creatives can prevent slotrenderended for unclear reasons. It would be undesirable for bidWon to depend on it. I am much less concerned about the targeting clear depending on it.

patmmccann avatar Oct 19 '26 15:10 patmmccann

I was not aware that some creatives can prevent slotRenderEnded from firing. I knew GAM viewability can fail for some creatives, but I had not run into slotRenderEnded missing before. Good catch, and it makes sense not to hard-depend bidWon on that event.

On why people read getTargetingMap() at slotRenderEnded: common cases are reporting, or refresh scheduling based on who won (e.g. bidder X → refresh in 60s, otherwise 30s). There are alternatives: pbjs.getAdserverTargeting() / getAdserverTargetingForAdUnitCode(), or listening earlier on GAM slotResponseReceived. So there are alternatives, for sure.

For me the main concern is consistency. If I listen to slotRenderEnded, should I expect hb_* to still be on the slot or not? I do not claim there is one correct product answer. I do care that the answer is the same on Safari and Chrome, instead of depending on whether bidWon won the race.

I also looked at Amazon APS (apstag.js). They clear their amzn* keys on slotRenderEnded, not when the bid is applied / “won.” They may simply not hit the “slotRenderEnded never fires” case as often, depending on creative mix. I do not know if they have a fallback when that event is missing.

As a conclusion: clearing targeting on bidWon and/or slotRenderEnded seems right, as long as there is no hard dependency on slotRenderEnded alone (with a timeout). That matches the direction in #15821.

bozghiyy avatar Oct 21 '26 06:10 bozghiyy