function getMetaValue(propName) { const meta = Array.from(document.getElementsByTagName("meta")).find( (meta) => meta.getAttribute("property") === propName || meta.getAttribute("name") === propName ); return meta ? meta.getAttribute("content") : undefined; } function extractMetadata() { const title = document.title; const url = window.location.href; const description = getMetaValue("og:description") || getMetaValue("description"); return { title, url, description }; } browser.runtime.onMessage.addListener(function (request, sender, sendResponse) { if (request.action === "getMetadata") { sendResponse(extractMetadata()); } });