On this page
When a page uses JavaScript, the links visible to a visitor may not all appear as anchor elements in the initial HTML. To check which links a page publishes, compare its source with the live DOM in browser DevTools. This guide shows how to inspect both and resolve a link’s destination without assuming that the destination works or is crawlable.
Key Takeaways
- View source shows an HTML source representation; the DevTools Elements or Inspector panel shows the current DOM, including changes made by JavaScript.
- A link’s written
hrefcan be relative. Its resolved destination also depends on the document URL and any applicable<base>element. - A visible anchor or resolved URL does not prove that the destination is reachable, that a crawler discovered it, or that the destination can be indexed.
- Source views, network responses, and live DOM snapshots can differ; capture the response for the specific navigation when that distinction matters.
Page source versus the live DOM
The browser parses HTML into a document object model, or DOM. Scripts can then add, remove, or change elements. DevTools displays that current structure, so a link inserted after load can appear in the DOM even when no corresponding anchor was present in the initial HTML.
Source inspection and DOM inspection answer different questions:
| View | Question it helps answer | Limitation |
|---|---|---|
| Page source | What HTML source is the browser showing? | It does not represent subsequent DOM changes. |
| DevTools Elements or Inspector | What elements exist in the DOM now? | It does not by itself show whether an element was in the original response. |
| DevTools Network response | What response was recorded for a particular document request? | The result depends on the captured request, including redirects, caching, and any service worker. |
view-source: is a browser feature, not a URL scheme that the website itself serves as an endpoint. In browsers that support it, it tells the browser to show source for the address that follows. It should not be copied into a site’s links as though it were an ordinary web URL.
Browser verification note: Current view-source: behavior and menu labels could not be verified for individual browsers in this environment. In a browser that supports the feature, try its View Page Source command or prepend view-source: to an HTTP or HTTPS page address. If that is unavailable, use DevTools Network to inspect the document response instead. Browser interfaces and behavior can vary.
Advertisement
How to view page source links in browser tools
1. Inspect the HTML source
Open the page, then use the browser’s View Page Source command if available. Search the source for <a or for a distinctive piece of link text. For a specific request, you can instead open DevTools, select the Network panel, reload with recording enabled, and inspect the response for the document request.
A source view is not necessarily an exact record of the response that created an already open tab: requesting source separately can produce a different response. Use the Network panel for the navigation you are investigating when you need to compare the actual captured response with its DOM. Check redirect entries and whether a service worker or cache may have affected the response.
2. Inspect the live link
Open DevTools on the original page and select its Elements or Inspector panel. Find the anchor by searching for its text or using the element picker. Inspect its href attribute and compare it with the source or captured response.
For an anchor with a known ID, the Console can show both the attribute value and the browser-resolved destination:
const link = document.querySelector('#sample-link');
if (link instanceof HTMLAnchorElement) {
console.log('Attribute:', link.getAttribute('href'));
console.log('Resolved:', link.href);
} else {
console.log('Anchor not found');
}
getAttribute('href') returns the current attribute value, which may have been changed by script; link.href resolves a present relative href against the document’s base URL. Neither value is a network check. If the attribute is missing, do not treat the property as evidence of a navigable destination.
The DOM is a snapshot, not a permanent inventory. Repeat the inspection after the relevant interaction, delayed rendering, or client-side navigation. Elements in a separate frame have their own document; inspect that frame as well if it is part of the page you are auditing.
3. Understand relative links and <base>
For a document at https://example.com/docs/page.html, an href of ../guide normally resolves to https://example.com/guide. A <base href="https://example.com/docs/"> can change the base used for relative URLs, as can a different document URL after navigation. Inspect document.baseURI in the Console to see the current base used for resolution.
A fragment such as #details can resolve to the current document with that fragment, while an absolute https: URL supplies its own destination. Also distinguish ordinary web links from values such as mailto: or javascript:; they are not HTTP page destinations.
Try a small comparison
Save the following as link-demo.html and open it in a browser. The example uses no dependencies. Its base URL is illustrative; the example does not require the destination pages to exist.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Link inspection demo</title>
<base href="https://example.com/docs/">
</head>
<body>
<a id="sample-link" href="../guide">Guide</a>
<div id="links"></div>
<script>
window.setTimeout(() => {
const link = document.createElement('a');
link.id = 'later-link';
link.href = 'later';
link.textContent = 'Added later';
document.querySelector('#links').appendChild(link);
}, 1000);
</script>
</body>
</html>
In the source, look for the sample-link anchor and the script that creates another anchor. In the live DOM, inspect again after the delay: the script is intended to add later-link to the document. The script itself is present in the source, but the added anchor is created at runtime.
Run the Console snippet above to compare ../guide with its resolved destination. With the example’s base, it should resolve to https://example.com/guide. Inspect later-link in DevTools as well: it should resolve relative to the same base. These examples were not executed in this environment; check the behavior in your target browser.
Advertisement
Check the destination separately
Finding an anchor establishes that it was present in the inspected source or DOM at that moment. It does not establish that a request succeeds, that a redirect ends at the intended page, or that a search engine can discover or index the destination.
For an authorized check, open the resolved destination and use the Network panel to inspect the document request, redirects, and final response. A successful response in your session can still differ from what another user or crawler receives because of authentication, cookies, request handling, or access restrictions. For crawlability, examine the relevant crawler’s rendering and discovery behavior and the site’s access and indexing controls; a browser inspection alone is insufficient.
Common Mistakes
- Searching only the source: A script may create the anchor later. Conversely, text in a script is not necessarily a link in the DOM.
- Treating a relative
hrefas a complete destination: Checkdocument.baseURIand the resolvedhref, especially when a<base>element is present. - Comparing different requests as if they were identical: A separately opened source view can differ from the response used by the tab under inspection.
- Assuming presence means success or crawlability: Test the destination and investigate crawler behavior separately.
- Inspecting too early: Delayed scripts, user actions, or client-side navigation can change the link set.
Best Practices
Record the page URL, inspection time, relevant interaction, and whether you checked source, a captured network response, or the live DOM. Compare the same navigation where possible, and repeat the check in the browsers and user states that matter to your application. Avoid sharing URLs containing private query parameters or credentials in audit notes.
Conclusion
Use source or a captured document response to inspect initial markup, and DevTools to inspect links that exist in the live DOM. Resolve relative URLs against the current base, then verify destination behavior and crawlability with separate checks.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.