Skip to main content

Find a canonical changed by JavaScript

Glot Rank Team · Published

Preserve both observations when a crawler reports the expected canonical but the browser shows another URL. They may describe different stages of the same page rather than a broken tool.

Eoghan Henn’s signed canonical experiment separates its 2018 test from later documentation updates. He used multiple test URLs and comparison pages to investigate script-inserted canonicals. Those historical observations are not a current processing timetable. Check today’s implementation against Google’s JavaScript guidance.

Keep three independent records

Choose an affected URL and an apparently unaffected page using the same template. Confirm their tasks and intended canonical addresses. Save dates, final URLs and access conditions.

RecordWhere to obtain itQuestion it answers
Document responseNetwork document headers and ResponseWhat HTML was delivered, and whether a header also declares a canonical
Rendered DOMElements or a read-only Console query after loadWhich canonicals this browser contains after script execution
Indexed recordSearch Console URL InspectionWhich canonical Google selected in that indexed record

Neither a live test nor the current DOM establishes Google’s indexed selection. Preserve an unavailable field rather than reporting acceptance.

Read every declaration, not just the first

On your own test page, use this read-only Console query:

[...document.querySelectorAll('link[rel~="canonical"]')]
  .map((link) => link.href);

Save the output and check whether declarations occupy a valid document location. This query excludes HTTP Link headers and does not establish what Google received.

In our teaching scenario, the original HTML names the product URL, while the loaded DOM contains both that URL and a category URL. Investigate the duplicate or conflicting implementation before accepting a tool’s first returned value as proof of correctness.

Locate the moment it changes

In development, repeat the observation after initial load, client navigation, consent changes and component loading. Record the first step that changes the declaration. In development, right-click the existing canonical element in Elements and choose Break on, then Attribute modifications. For inserted or removed declarations, set a Subtree modifications breakpoint on head. When execution pauses, inspect the Sources Call Stack and save the mutation location and callers. See Chrome’s DOM-breakpoint instructions. Use source search to identify the component or tag rather than disabling unfamiliar production scripts.

Check whether the shared head, an SEO plugin, a tag manager and the client router all write the field. The repair needs a defined owner for the canonical implementation rather than competing writers that depend on execution order.

URL and intended canonical:
Response HTML and HTTP headers:
DOM before/after and the triggering step:
Comparison page on the same template:
Located component or tag and owner:
Change scope and shared pages:
Acceptance: delivered and rendered declarations agree; conflicts resolved
Follow-up: dated Google-selected canonical, or an unavailable record

Repeat navigation after repairing the template

For the same current URL, JavaScript should not change a canonical declared in the response HTML to a different address. After client navigation from A to B, compare B’s DOM with the response from opening B directly; do not label A’s response and B’s DOM a conflict. If script insertion is genuinely necessary, follow Google’s consistency and single-declaration guidance rather than deploying a historical experiment across the site.

Retest direct entry, client navigation, reload and browser back/forward. Sample other pages sharing the template. Save the before-and-after records: correct current declarations are an implementation outcome; indexed selection and search effects require later evidence.

Use the canonical investigation when deciding how two pages should relate. This worksheet identifies who changed a declaration; it does not justify deleting content from a canonical string alone.