Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: Ad Calls Prevented When document.body Isn’t Ready #11927

Closed
lksharma opened this issue Jul 4, 2024 · 5 comments
Closed

Issue: Ad Calls Prevented When document.body Isn’t Ready #11927

lksharma opened this issue Jul 4, 2024 · 5 comments
Labels

Comments

@lksharma
Copy link
Collaborator

lksharma commented Jul 4, 2024

Description
In version 9.4 and later, a change was introduced that prevents ad calls from being made if document.body isn’t ready. This issue is linked to the changes made in this commit, which added a location method for cross-frame creatives.

Affected Version: 9.4+
Introduced in: PR #11863
Test Page: https://30f9d51a.demo-ann.pages.dev/testpage

Steps to Reproduce

  1. Visit the Test Page: Open the test page provided.
  2. Check the Console: Observe the console for errors related to appendChild caused by adRendering.js#L258
  3. verify no ad calls are made for configured bidder (ex: /openrtb/pbjs)

Expected Behavior
Ad calls should be made regardless of whether document.body is fully loaded or not and no Uncaught error should be thrown by pbjs

Actual Behavior
When document.body isn’t ready, the following error is thrown, preventing ad calls from going out:

TypeError: Cannot read properties of null (reading 'appendChild')
    at insertLocatorFrame (adRendering.js:258:19)
    at pbjsInstance.processQueue (prebid.js:979:21)

Analysis

  • The error originates from the insertLocatorFrame function in adRendering.js#L258.
  • The issue arises when pbjs is loaded synchronously or when document.body isn’t available at the time of appendChild call.
  • This problem does not occur when pbjs is loaded asynchronously because the script execution is deferred until document.body is available.

Proposed Solution
Ensure that document.body is ready before attempting to call appendChild. A potential solution is to check for the existence of document.body before executing insertLocatorFrame.

export function insertLocatorFrame() {
  if (!window.frames[PB_LOCATOR]) {
    const frame = createInvisibleIframe();
    frame.name = PB_LOCATOR;
    if (document.body) {
      document.body.appendChild(frame);
    }
  }
}
@olafbuitelaar
Copy link
Contributor

this should solve it; #11926

@lksharma
Copy link
Collaborator Author

lksharma commented Jul 4, 2024

Thank you

@patmmccann
Copy link
Collaborator

Thank you!

@patmmccann
Copy link
Collaborator

Do we think this warrants a patch release to 9.4?

@lksharma
Copy link
Collaborator Author

lksharma commented Jul 6, 2024

A patch release for version 9.4 makes sense to me since it affects the ability of ad calls to go through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

3 participants