Closed jridgewell closed 7 years ago
I'll take a look, but first impression is that it's not related to #6241.
@jridgewell Is there any actual error here? What's the browser?
No error message, all coming from iOS Safari 10.1.1.
The no error message will likely be fixed by https://github.com/ampproject/amphtml/pull/6428 once we push out canary.
Might be. Is this a new error? How many of these errors are there? From what I can tell, this happens when document.defaultView == null
which is sometimes possible when the iframe is removed.
/to @avimehta Is it possible we keep a reference to a friendly iframe elements somewhere in analytics after an embed is removed?
yes, we do that afaik. Aren't ads iframes removed if they go out of the view and beyond some threshold? visibility code keeps references around afaik.
They're very infrequent, and I'm unsure if they're new.
I doubt a4a iframes get removed. But let's confirm if this is the case first. If indeed the case - it's a minor issue since no prod features are affected.
From what I see, the error starts in the instrumentation.js
in:
listenOnceFunc(spec, vars => {
const el = getElement(this.ampdoc, spec['selector'],
analyticsElement, spec['selectionMethod']);
if (el) {
const attr = getDataParamsFromAttributes(el, undefined,
VARIABLE_DATA_ATTRIBUTE_KEY);
for (const key in attr) {
vars[key] = attr[key];
}
}
callback(new AnalyticsEvent(eventType, vars));
}, shouldBeVisible, analyticsElement);
And then eventually fails in amp-analytics.js
in handleRequestForEvent_
:
return urlReplacementsForDoc(this.element).expandAsync(request)
Whether it's a trigger on "visible" or "hidden" - I can't tell yet.
So, if it's a hidden
event - I think an easy way to repro this would be to get a sample document with a A4A embed and send this document unload
signal.
Ok. I'm almost certain that this error is benign. @avimehta what's your opinion?
I actually found a way to repro this 100% of the time in the a4a.amp.html sample. Simply calling $0.unlayoutCallback()
on the first ad element. In a short order, it fails for the "timer" trigger.
I have partial fix. A fuller fix would likely take some deeper refactoring to disconnect all events from the destroyed analytics tag.
Relevant line is https://github.com/ampproject/amphtml/blob/0310284ed51e6e0ad0addd2371a9f3dc491a8204/src/service.js#L338
Is this fixed by https://github.com/ampproject/amphtml/pull/6241?