amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

"Ampdoc for shell has not been installed" in shadow document

Open danielrozenberg opened this issue 8 years ago • 16 comments

AMP ad not collapsing (similar to #12645) on all browsers in a shadow document, e.g., the same webpage as in the referenced bug:

https://rep.repubblica.it/pwa/commento/2018/01/10/news/il_galateo_di_serracchiani_per_il_bon_ton_dei_sindaci-186240380/

This does not happen in the base AMP page that the PWA loads:

https://rep.repubblica.it/ws/detail/commento/2018/01/10/news/il_galateo_di_serracchiani_per_il_bon_ton_dei_sindaci-186240380

Error message from console:

Unable to load ad implementation for type  doubleclick , falling back to 3p, error:  Error: Ampdoc for shell has not been installed
Stack trace:
wa@https://cdn.ampproject.org/shadow-v0.js:8:169
f.createError@https://cdn.ampproject.org/shadow-v0.js:4:33
f.getAmpDoc@https://cdn.ampproject.org/shadow-v0.js:187:109
K@https://cdn.ampproject.org/rtv/001528909142235/v0/amp-ad-network-doubleclick-impl-0.1.js:12:33
H@https://cdn.ampproject.org/rtv/001528909142235/v0/amp-ad-network-doubleclick-impl-0.1.js:11:909
O@https://cdn.ampproject.org/rtv/001528909142235/v0/amp-ad-network-doubleclick-impl-0.1.js:17:590
wb@https://cdn.ampproject.org/rtv/001528909142235/v0/amp-ad-network-doubleclick-impl-0.1.js:26:148
f/g.initLifecycleReporter@https://cdn.ampproject.org/rtv/001528909142235/v0/amp-ad-network-doubleclick-impl-0.1.js:192:253
pe@https://cdn.ampproject.org/rtv/001528909142235/v0/amp-ad-network-doubleclick-impl-0.1.js:168:48
f/Z.prototype.upgradeCallback/</</</<@https://cdn.ampproject.org/rtv/001528909142235/v0/amp-ad-0.1.js:107:425
 log.js:164:6

What browsers are affected?

Reproducible on Chrome & Firefox

Which AMP version is affected?

Canary release 1528909142235 (tracking issue #16025)

danielrozenberg avatar Jun 14 '18 15:06 danielrozenberg

@keithwrightbos any recent change in amp-ad-network-doubleclick-impl.js ? It's very new in current canary (was cut this Tuesday).Seems amp-ad-network-doubleclick-impl thrown when getting instantiated.

lannka avatar Jun 14 '18 15:06 lannka

/cc @adelinamart; it sounds like this is a regression in the current canary

mrjoro avatar Jun 14 '18 15:06 mrjoro

Took a quick look, both a4a impl and 3p fallback failed at the same code point:

        Services.documentInfoForDoc(opt_nodeOrDoc || win.document).pageViewId);  (utils.js:438)

@choumx any recent change could have ampdoc service failed?

lannka avatar Jun 14 '18 15:06 lannka

The line referenced is not new and so I wouldn't expect this to be related to changes within doubleclick impl code.

keithwrightbos avatar Jun 14 '18 15:06 keithwrightbos

I didn't promote opt-in canary to 1% . Marking this as P0. Can you let me know what's the latest status here. Thank you.

adelinamart avatar Jun 14 '18 16:06 adelinamart

Not sure what changed to cause this in canary. A bit of a tangent but this conditional seems wrong:

https://github.com/ampproject/amphtml/blob/b40d6b681195ca766cd00dd55b2425824731336e/src/service/ampdoc-impl.js#L105-L112

Looks like it should be gated under isExperimentOn(win, 'ampdoc-shell').

dreamofabear avatar Jun 14 '18 16:06 dreamofabear

Still happening. More console errors:

Unable to load ad implementation for type  doubleclick , falling back to 3p, error:  Error: No ampdoc found for [object HTMLDocument]
    at wa (shadow-v0.js:8)
    at sa.f.createError (shadow-v0.js:4)
    at sh.f.getAmpDoc (shadow-v0.js:187)
    at K (amp-ad-network-doubl…lick-impl-0.1.js:12)
    at H (amp-ad-network-doubl…lick-impl-0.1.js:11)
    at O (amp-ad-network-doubl…lick-impl-0.1.js:17)
    at wb (amp-ad-network-doubl…lick-impl-0.1.js:26)
    at pe.push.f.g.initLifecycleReporter (amp-ad-network-doubl…ick-impl-0.1.js:192)
    at new pe (amp-ad-network-doubl…ick-impl-0.1.js:168)
    at amp-ad-0.1.js:107

No ampdoc found for [object HTMLDocument]
me	@	shadow-v0.js:81
(anonymous)	@	shadow-v0.js:495
(anonymous)	@	shadow-v0.js:8
setTimeout (async)		
y	@	shadow-v0.js:8
(anonymous)	@	shadow-v0.js:254
Promise.catch (async)		
b.Sf	@	shadow-v0.js:253
b.upgrade	@	shadow-v0.js:238
ei	@	shadow-v0.js:269
dm	@	shadow-v0.js:470
(anonymous)	@	shadow-v0.js:470
Td	@	shadow-v0.js:75
cm	@	shadow-v0.js:470
(anonymous)	@	shadow-v0.js:470
(anonymous)	@	shadow-v0.js:472
(anonymous)	@	shadow-v0.js:472
Promise.then (async)		
am	@	shadow-v0.js:472
(anonymous)	@	shadow-v0.js:471
f.installExtensionsInDoc	@	shadow-v0.js:471
(anonymous)	@	shadow-v0.js:503
Em	@	shadow-v0.js:502
Dm.attachShadowDoc	@	shadow-v0.js:503
(anonymous)	@	news-app.html:36765
(anonymous)	@	shadow-v0.js:497
Promise.then (async)		
c	@	shadow-v0.js:497
Promise.then (async)		
c	@	shadow-v0.js:497
zm	@	shadow-v0.js:498
Cm	@	shadow-v0.js:499
(anonymous)	@	shadow-v0.js:511
(anonymous)	@	shadow-v0.js:512

Uncaught Error: No ampdoc found for [object HTMLDocument]
    at wa (shadow-v0.js:8)
    at sa.f.createError (shadow-v0.js:4)
    at sh.f.getAmpDoc (shadow-v0.js:187)
    at N (amp-ad-0.1.js:11)
    at L (amp-ad-0.1.js:11)
    at Ta (amp-ad-0.1.js:45)
    at new pc (amp-ad-0.1.js:86)
    at amp-ad-0.1.js:108

danielrozenberg avatar Jun 15 '18 15:06 danielrozenberg

I can't figure out how to reproduce this locally. Heisenbugs make me sad :( reassigning to @choumx for another look

danielrozenberg avatar Jun 15 '18 16:06 danielrozenberg

Turns out this is actually not a regression. It repros consistently on canary because a4aProfilingRate experiment is 1, but only 0.1 on prod.

The root bug is that getServiceForDoc(nodeOrDoc) will throw an error if called before buildCallback(). This is because getAmpDoc() is not available until then.

The call stack starts in the AmpAdNetworkDoubleclickImpl constructor:

https://github.com/ampproject/amphtml/blob/62ab579756f287ad7f4627d68bf203c503be3484/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js#L263-L264

Stack:

amp-ad-network-doubleclick-impl.js#AmpAdNetworkDoubleclickImpl()
amp-ad-network-doubleclick-impl.js#initLifecycleReporter()
google-data-reporter.js#googleLifecycleReporterFactory()
google-data-reporter.js#getLifecycleReporter()
google-data-reporter.js#setupPageLoadMetricsReporter_()
utils.js#getCorrelator()

Then, getCorrelator() finally calls Services.documentInfoForDoc(). One possible fix is to move the first call to buildCallback().

FWIW, the conditional that causes this to inconsistently repro on prod is in getLifecycleReporter(): https://github.com/ampproject/amphtml/blob/62ab579756f287ad7f4627d68bf203c503be3484/ads/google/a4a/google-data-reporter.js#L64-L67

dreamofabear avatar Jun 15 '18 18:06 dreamofabear

Downgrading to P1 since this is not a regression.

/to @keithwrightbos for fixing the root ads bug.

dreamofabear avatar Jun 15 '18 18:06 dreamofabear

@danielrozenberg @choumx So we are ok with the error, and not cherrypick the fix right?

zhouyx avatar Jun 18 '18 19:06 zhouyx

I don't think cherrypick is necessary since this isn't P0.

@keithwrightbos Thanks for the quick fix.

dreamofabear avatar Jun 19 '18 16:06 dreamofabear

Issue appears to still be occurring when using firefox on the current canary. Re-assigning to @choumx to triage. Thanks

No ampdoc found for [object HTMLDocument] shadow-v0.js:81:462

me https://cdn.ampproject.org/shadow-v0.js:81:462 bi/b.prototype.build/this.cd< resource.js:676:34

Error: failed to build: amp-ad#19: No ampdoc found for [object HTMLDocument] log.js:505:16

keithwrightbos avatar Jun 21 '18 15:06 keithwrightbos

Looks like this error (or a similar one) still happens on the page provided in #12645. Stack trace is very similar:

Powered by AMP ⚡ HTML shadows – Version 1529458017017

shadow-v0.js:81 No ampdoc found for [object HTMLDocument] <amp-ad type=​"doubleclick" data-slot=​"/​35012960/​repubblica.pwa/​dettaglio/​box1" width=​"300" height=​"250" class=​"i-amphtml-element i-amphtml-notbuilt amp-notbuilt i-amphtml-layout-fixed i-amphtml-layout-size-defined i-amphtml-error" style=​"width:​ 300px;​ height:​ 250px;​" data-amp-slot-index=​"0" data-a4a-upgrade-type=​"amp-ad-network-doubleclick-impl">​…​</amp-ad>​
me @ shadow-v0.js:81

log.js:505 Uncaught (in promise) Error: failed to build: amp-ad#19: No ampdoc found for [object HTMLDocument]
    at wa (log.js:505)
    at sa.f.createError (log.js:263)
    at sh.f.getAmpDoc (action-impl.js:386)
    at L (service.js:359)
    at I (service.js:268)
    at N (service.js:267)
    at ub (utils.js:438)
    at oe.push.f.g.initLifecycleReporter (utils.js:434)
    at oe.push.f.g.buildCallback (amp-ad-network-doubleclick-impl.js:509)
    at resource.js:662

This happens on version 1529458017017, which is the canary version that was cut yesterday

danielrozenberg avatar Jun 21 '18 15:06 danielrozenberg

Hmm. I think moving to buildCallback was necessary but insufficient, since getCorrelator() tries to find the service given window.document when it should be given a node in the shadow tree.

A fundamental problem is the complexity around runtime services WRT single-doc vs. PWA. Rather than serviceFor(<window>) and serviceForDoc(<nodeOrDoc>), we should have callers always pass the closest-to-leaf DOM node and the runtime will return the appropriately scoped service automatically. Plug for go/amp-roots.

dreamofabear avatar Jun 21 '18 21:06 dreamofabear

I have a potential fix in #16233 but looks like #16240 could also fix this by removing that code path entirely.

dreamofabear avatar Jun 22 '18 15:06 dreamofabear