ampproject / ampproject/amphtml
3p frames are not functional under custom 3p domain (non-localhost)
- Dominant language
- JavaScript
- Stars
- 14.9k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
## What's the issue?
Impossible to have properly functional 3p iframes when launching AMP project on self-hosted, public infrastructure. Specifically checked this with `amp-ad` frames, where none of the ad vendors loads, throwing error message `3p type for custom iframe not allowed`
## How do we reproduce the issue?
This is live example, a page with ads test found in the `examples` folder:
https://amp.firstimpression.io/examples/ads.amp.html
It is easy to see in console that an error is thrown per each ads vendor:
```
log.js:425 Uncaught Error: 3p type for custom iframe not allowed: a9
at Log.assert (log.js:425)
at userAssert (log.js:967)
at validateAllowedTypes (integration.js:788)
at window.draw3p (integration.js:706)
at frame.max.html:9
```
Contents of `custom-config.json` are:
```
{
"cdnUrl": "https://amp.firstimpression.io/",
"thirdPartyUrl": "https://amp-3p.firstimpression.io"
}
```
## Additional information
As far as I see the problem occurs in the function `validateAllowedTypes()` in [`integration.js`](https://github.com/ampproject/amphtml/blob/ee6d12c1b775270668caa85892b3640c6703b04f/3p/integration.js#L769) where none of the conditions is met. I guess this happens because the values from `custom-config.json`, `env` and `AMP_CONFIG` do not survive to the 3p iframe context, and all values of `config.urls` are default ("3p.ampproject.net", etc) in the frame.
I am not sure if this is related and caused by this, or is that a separate bug - while researching the problem found an issue in build scripts: https://github.com/ampproject/amphtml/blob/cd1e0c158d1d46e9a298f98f62ace60c6df135d0/build-system/tasks/default-task.js#L53
The call to `runPreBuildSteps()` is done with single parameter `true`, but it seems that the function should receive object of options (`{watch, minify, fortesting}`). All functions that are called inside `runPreBuildSteps()` also rely on `options` being a key-value object. Maybe I am missing something, but looks like an error?
## What browsers are affected?
All browsers
## Which AMP version is affected?
Version is 2008050741000. Looks like it was always like that by design.
cc @ampproject/wg-infra
Contributor guide
Research direction
Start with 3p/integration.js, especially validateAllowedTypes(), and reproduce the failure using the ads example and the supplied custom-config.json. Check how custom configuration reaches the 3p iframe, then review build-system/tasks/default-task.js and runPreBuildSteps() as a possible related issue. Done means the ad vendors load under the non-localhost custom 3p domain without the custom iframe error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100