Google loves AMP. I don't.
In fact, I really, really, really hate AMP. Not only does it remove functionality from pages, but it's a threat to the Open Web. Google call it an open standard and yet exercise complete control over what gets implemented into it.
My biggest bugbear though, is that despite numerous requests to allow users to turn it off, Google still hasn't provided a global means to disable this cretinous pile of crud.
Although it's (thankfully) less common now, you may also be directed to a Google hosted copy of the AMP page rather than the publisher's own servers. But either way, you're going to be pulling (and running) scripts from cdn.ampproject.org
If you're very lucky, then the AMP page you land on might include a link to the full canonical version (something Google have said they're going to make more accessible too), but a good many currently don't.
The position, basically, seems to be - eat this because it's being forced down your throat.
It's not much better for those running sites either. If you want to be featured in the much vaunted carousel, you'd better have AMP representations. But, if you serve AMP pages, the analytics you get back are much, much more limited and you can use a much more limited subset (and largely arbitrary) set of tags.
If limited analytics sound like a privacy win for you, keep in mind that Google is almost certainly still collecting all the same data, just making less available to those who are running your page. If the argument that analytics enable webmasters to improve their service holds any weight, then that's scuppered by the limited data in AMP too.
Better yet, they're also introducing AMP For Email - because what you really need in your inbox is emails that can change, or "interactive marketing".
For more reading, see
- How to turn off accelerated Mobile Pages
- Google AMP Sucks
- I decided to disable AMP on my site
- Kill Google AMP before it kills the web
- Google AMP Sucks (another one)
- The problem with AMP
- Google wants to use AMP to make email more interactive
- Hacker News on AMP for Email
Ranting about AMP aside, the aim of this script is to try and find you a proper representation of any AMP pages you have the misfortune to land upon. Unfortunately, there's no way to avoid hitting AMP pages initially (especially now that Twitter have decided it's better)
This repo contains a userscript for GreaseMonkey / TamperMonkey which simply pulls in the anti-amp code.
What the anti-amp script does, is
- attempt to check whether a loaded page is in AMP format (by checking for AMP specific markup)
- If it's not AMP, run no further
- Attempt to find the canonical URL within the markup and then redirect the browser to that URL
- If no canonical can be detected, inject a link to search DuckDuckGo by page title
The main function involved in this work isn't injected to the page (to avoid constantly injecting a large chunk), instead a small function is injected to load the main functionality via my CDN. Your browser (actually, the extension) will cache this file so won't need to fetch particularly regularly at all.
Although, like AMP, this means loading scripts from a central location, Unlike AMP, I take security reasonably seriously and use SubResourceIntegrity (SRI) to try and make sure that your browser will only run the script if it hasn't been tampered with in any way. In order to change this, an attacker would need to either create a hash collision or interfere with the script you have in Greasemonkey/Tampermonkey (if they can do that, you've got much bigger concerns).
The script is pulled in directly by GreaseMonkey/TamperMonkey once in a while, so won't result in referrer strings reflecting your browsing appearing in my logs.
Ultimately, this script is just part of some stuff I'm building to try and mitigate the effects of AMP on my devices (see MISC-25)
You'll need either GreaseMonkey or Tampermonkey (or something else compatible) installed in your browser.
- Visit this url - https://github.com/bentasker/RemoveAMP/raw/master/greasemonkey_hook.user.js - and *Monkey should prompt you to install it
If that doesn't work, select 'Create New Script' and paste the content of that URL in
Once the user-script is enabled, if you want to verify behaviour, browse to My simple test page, this should automatically result in you being redirected to the canonical version of that page.
Depending on your choice of browser and extension (TamperMonkey on Chrome is unaffected,for example) some sites running certain Content-Security-Policies may well refuse to run the ant-amp code (and trigger a warning in console, as well as to the report-uri, if defined).
A couple of additional scripts are also provided:
- https://github.com/bentasker/RemoveAMP/raw/master/greasemonkey_hook_googlesearch.user.js - Implemented for FKAMP-2 to work around the fact Google doesn't declare it's AMP as AMP when a search result link is clicked.
- https://github.com/bentasker/RemoveAMP/raw/master/redirect_to_non_amp_sites.user.js - Implemented for FKAMP-4 as a nuclear option. Domains that fail to properly implement AMP (cough... Google News) get redirected to a domain that isn't so user hostile (hey, Bing's actually better than Google at something!).
Copyright © B Tasker 2018 Released under GNU GPL V3