set / read rel=canonical

by johnmu

HTML

<p>
Read more about the request, not from automated crawlers.
Another reason could also be labeled as non-transcoded in search Console.
</p>

JavaScript

var ROBOTS_SELECTOR = "meta[name='robots']";

// create meta robots if none exists
if (!document.querySelector(ROBOTS_SELECTOR)) {
  var ln = document.createElement("meta");
  ln.name = "robots"; ln.content="{}";
  document.head.appendChild(ln);
}

// set meta robots
document.querySelector(ROBOTS_SELECTOR).setAttribute("content", "noindex, domagic");

// show the meta robots after a short time, in case the rest needs time to be processed.
// use this JS on the bottom of your page to test it
setTimeout( function() { 
  // read current meta robots, assuming there is one
  var robotsMeta = document.querySelector(ROBOTS_SELECTOR)? document.querySelector(ROBOTS_SELECTOR).content:"n/a";

  // display on top
  var info = document.createElement("h1");
  info.appendChild(document.createTextNode("robots: " + robotsMeta));
  document.body.insertBefore(info, document.body.firstChild);
}, 1000) ;
// done