How do I dynamically insert html tags in <head></head>?

I’m trying to do this for some pages:

<link rel="canonical" href="https://www.example.com/preferred-page-url" /> tag in the <head>

I think this is currently possible just with the Cloudflare Workers, or with Custom JS, but I’m guessing you need it for Crawlers so that wouldn’t work (JS)