ampproject / ampproject/amphtml
amp-script requests text/plain for same origin src, but requires text/javascript response
- Dominant language
- JavaScript
- Stars
- 14.9k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
## What's the issue?
AMP is requesting text/plain for for same origin requests, but if text/plain is returned, it throw the error:
Uncaught (in promise) Error: amp-script Same-origin "src" requires "Content-Type: text/javascript" or "Content-Type: application/javascript". Fetched source for amp-script[src="..."].js has "Content-Type: text/plain". See https://amp.dev/documentation/components/amp-script/#security-features.
## How do we reproduce the issue?
See:
https://facebook.engagetosell.com/test/AMP_fail/test_406.html
Unfortunately, this public facing server will not return a 406 when text/plain is requested for a JS file, but you can clearly see (using the browser's dev tools) that the request for 12981.js has a request Accept header of "text/plain". This server (NGINX) still returns the JS file with Content-Type "text/javascript", but others (e.g. IIS) will not. Instead, they return a 406 response.
This test page does show the error in the console for the amp-script with src="12981.js.txt".
## What browsers are affected?
All browsers. Presumably. I tested Chrome and FF.
## Which AMP version is affected?
I don't know if this was always broken. I am new to AMP.
Powered by AMP ⚡ HTML – Version 2007302351001
Contributor guide
Research direction
Start with the amp-script handling for same-origin src requests and inspect how the Accept header is set and how the response Content-Type is checked. Reproduce the issue using the linked test page and browser developer tools, including the 12981.js and 12981.js.txt cases. Done should mean same-origin amp-script requests no longer fail or receive a 406 because the requested and returned JavaScript content types are incompatible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100