ampproject / ampproject/amphtml

amp-analytics: PerformanceObserver cannot be used to report most cross-origin LongTask events

Open
#36,136 1 comment 0 reactions 0 assignees View on GitHub
Stale Type: Bug
Dominant language
JavaScript
Stars
14.9k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

### Description

In my testing, unit test "amp-analytics.iframe-transport: logs poor performance of vendor iframe" consistently fails:
```
$ amp unit --files extensions/amp-analytics/0.1/test/test-iframe-transport.js
...
FAILED TESTS:
amp-analytics.iframe-transport

● logs poor performance of vendor iframe
Chrome 94.0.4606.54 (Linux x86_64)
Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
```

This test points to a real problem. In `extensions/amp-analytics/0.1/iframe-transport.js`, method `processCrossDomainIframe()` creates a `PerformanceObserver` after a cross-origin iframe is attached to the page. While [w3c documentation](https://github.com/w3c/longtasks#demo) claims that cross-origin iframes can be monitored, it seems this isn't the case in practice. At least for Chromium, we can only expect `cross-origin-descendant` longtask reports when an iframe...
* is on the same origin as the parent frame but is sandboxed (e.g. `iframe.sandbox = "allow-scripts"`), or
* is on a subdomain of the parent frame (e.g. parent is example.com and child iframe is a.example.com), or
* has a special about: or data: src

Importantly, we cannot expect `cross-origin-descendant` longtask reports in Chromium if the iframe `src` points to any other root domain than the parent frame's location. This was explained to me when I filed [Chromium Issue 1231864](https://bugs.chromium.org/p/chromium/issues/detail?id=1231864). A key takeaway is that these pages on other root domains run in different processes (this is why performance monitoring will not be implemented by Chromium, apparently). Since they're in different processes, perhaps this longtask warning is unnecessary?

I would guess that the vast majority of iframes created by `processCrossDomainIframe()` are on different root domains than the parent frame. What does the team think about removing `createPerformanceObserver_()` from `extensions/amp-analytics/0.1/iframe-transport.js`?

### Reproduction Steps

Run unit test `amp unit --files extensions/amp-analytics/0.1/test/test-iframe-transport.js` and see failure of test `amp-analytics.iframe-transport: logs poor performance of vendor iframe`.

### Relevant Logs

_No response_

### Browser(s) Affected

Chrome

### OS(s) Affected

Ubuntu 21.04 64bit

### Device(s) Affected

_No response_

### AMP Version Affected

(main branch as of 22 Sep 2021, 6:00 AM PDT)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.