Error: undefined is not an object (evaluating 'b.document.querySelector')
stack trace:
Error: undefined is not an object (evaluating 'b.document.querySelector') at querySelector (https://raw.githubusercontent.com/ampproject/amphtml/1527203409437/extensions/amp-ad-exit/0.1/filters/click-location.js:85) at getScrollTop (https://raw.githubusercontent.com/ampproject/amphtml/1527203409437/src/service/viewport/viewport-impl.js:486) at getBoundingClientRect (https://raw.githubusercontent.com/ampproject/amphtml/1527203409437/src/service/viewport/viewport-impl.js:438) at (https://raw.githubusercontent.com/ampproject/amphtml/1527203409437/src/service/url-replacements-impl.js:712) at service (https://raw.githubusercontent.com/ampproject/amphtml/1527203409437/src/services.js:299) at (https://raw.githubusercontent.com/ampproject/amphtml/1527203409437/src/service/resources-impl.js:2148)
Sample referrer:
Referrer https://www-comingsoon-it.cdn.ampproject.org/v/s/www.comingsoon.it/tv/anticipazioni/le-verita-nascoste-stasera-la-seconda-puntata-le-anticipazioni-di-venerdi-1/n78809/amp/?amp_js_v=0.1&usqp=mq331AQECAEoAQ%3D%3D User agent Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.0 Mobile/14G60 Safari/602.1 Service default-cdn-1p-canary Version 001527816702194
This error is throwing because the click-location.js library includes the line:
const relativeElement = win.document.querySelector(
this.relativeTo_);
in the function onLayoutMeasure.
Per Issue https://github.com/ampproject/amphtml/issues/14936 and PR https://github.com/ampproject/amphtml/pull/15214, we deprecated onLayoutMeasure in favor of onMeasureChanged. We should re-evaluated the use of onLayoutMeasure here to see if it should use onMeasureChanged instead.
Why would onLayoutMeasure/onMeasureChanged affect the presence of querySelector? Would the window or document not be available in onLayoutMeasure?
These are good questions. @alabiaga would you or someone from the runtime team know?
Since these filters are initialized in buildCallback, which is guaranteed to happen before onLayoutMeasure, I can't think of a reason why win would be null, unless this.win = toWin(element.ownerDocument.defaultView) is returning null or some kind of race condition is happening between onLayoutMeasure and buildCallback.
It also does seem like the use case for onLayoutMeasure here is different from a proxy to resize, hence the bug and situation I referenced above fro onMeasureChanged is not applicable. This sounds more like a runtime issue than an issue with the extension itself.
So after syncing with @lannka, this bug seems to be a lot more intractable than I thought it was because since it happens in the ad itself, all the log referrers are completely useless, since it's not the advertisers and not the publishers that would use <amp-ad-exit>. It also doesn't seem to repro locally.
This bug was filed as high priority because our logs see this error on average about 500 times every 48 minutes and ranks 5th in occurrence frequency for all our error logs in production. If it doesn't cause any user-visible issues, feel free to downgrade. It still seems like a legit bug though....
Another clue: https://github.com/ampproject/amphtml/issues/15759. This bug traces to the buildCallback of amp-ad-exit, which is very odd. It seems like amp-ad-exit's buildCallback is somehow triggering logic that should happen in click-location.js's onLayoutMeasure. I'm not sure why though.
Hey Cathy, I am at a roadshow but will investigate when I get a chance. Thanks
i believe Justin addressed this here #16469. Will audit logs when the change is out in prod.
@alabiaga I think Justin's PR might not address this issue because amp-ad-exit is not in the AMP doc but in an A4A iframe embed. Justin's PR mutes error messages if the AMP doc window is detached.
@lannka sounds good. lets assign to me to investigate. thanks
@alabiaga I believe this issue have the same root cause as #17345, we can continue the discussion there.