I have a Chrome extension browser action that extracts the metadata from a current tab. It works as expected, except on certain webpages (e.g., YouTube) where elements (e.g., description) are not from the current page, but are from the homepage (or where the last manual page refresh occurred within the same domain). The title and URL are always being retrieved correctly, but using different code (chrome.tabs.query).
An example of the script code for meta description (using chrome.tabs.executeScript):
var descriptionElement = document.querySelector("meta[name=\'description\']");
if (descriptionElement != null)
descriptionElement = descriptionElement.getAttribute("content");
This code will return, "Share your videos with friends, family, and the world" (which is the homepage meta description) on any YouTube.com page, unless I reload the page or arrive there from a direct link.
I've noticed that the original HTML ("View page source") is always correct, but Chrome Developer Tools Elements is displaying the incorrect head data.
How can I extract the current tab without requiring a full page reload? Is there a way other than querySelector that can bypass the browser's rendering and access the HTML directly?