Các bước thực tế
Mở trang cần kiểm tra và bảng điều khiển dành cho nhà phát triển của trình duyệt. Với công cụ kiểm tra tràn trên di động, trước tiên hãy bật chế độ responsive.
Xem xét mã, dán toàn bộ đoạn script vào console rồi nhấn Enter. Script đọc trang hiện tại; chỉ công cụ kiểm tra metadata sitemap và các bộ kiểm tra cùng origin mới gửi request có giới hạn.
Xem kết quả trong console hoặc CSV/JSON tải xuống. Chính sách trình duyệt, trạng thái xác thực và phương thức máy chủ không được hỗ trợ có thể khiến một số phép kiểm tra chưa kết luận được.
Script dành cho console của trình duyệt
Xem xét trước khi chạy. Script đọc trang hiện tại; chỉ các lần kiểm tra sitemap và liên kết mới gửi request cùng origin có giới hạn. Request không gửi cookie; script không thay đổi nội dung website.
(() => {
const meta = (name, attr = 'name') => document.querySelector('meta[' + attr + '="' + name + '"]')?.content || '';
const links = (rel) => [...document.querySelectorAll('link[rel="' + rel + '"]')].map((node) => ({ href: node.href, hreflang: node.hreflang || '' }));
const report = {
url: location.href,
title: document.title,
titleLength: document.title.length,
description: meta('description'),
descriptionLength: meta('description').length,
robots: meta('robots'),
canonical: links('canonical')[0]?.href || '',
language: document.documentElement.lang || '',
headings: Object.fromEntries([1, 2, 3, 4, 5, 6].map((level) => ['h' + level, [...document.querySelectorAll('h' + level)].map((node) => node.innerText.trim()).filter(Boolean)])),
hreflang: links('alternate').filter((item) => item.hreflang),
openGraph: Object.fromEntries([...document.querySelectorAll('meta[property^="og:"]')].map((node) => [node.getAttribute('property'), node.content])),
twitter: Object.fromEntries([...document.querySelectorAll('meta[name^="twitter:"]')].map((node) => [node.name, node.content])),
jsonLdBlocks: document.querySelectorAll('script[type="application/ld+json"]').length,
};
console.table({ title: report.title, titleLength: report.titleLength, descriptionLength: report.descriptionLength, robots: report.robots, canonical: report.canonical, language: report.language, h1Count: report.headings.h1.length, hreflangCount: report.hreflang.length, jsonLdBlocks: report.jsonLdBlocks });
console.log('Full SEO page report:', report);
const link = document.createElement('a');
link.href = URL.createObjectURL(new Blob([JSON.stringify(report, null, 2)], { type: 'application/json' }));
link.download = 'seo-page-audit.json';
link.click();
setTimeout(() => URL.revokeObjectURL(link.href), 1000);
})();