(browser: Playwright)
| 34 | } |
| 35 | |
| 36 | async function getMetadataMetas(browser: Playwright) { |
| 37 | const metas = await browser.locator('meta').evaluateAll((elements: any[]) => { |
| 38 | return elements |
| 39 | .filter((meta) => { |
| 40 | if (!meta.name && !meta.hasAttribute('property')) { |
| 41 | return false |
| 42 | } |
| 43 | |
| 44 | const attr = meta.name || meta.getAttribute('property') || '' |
| 45 | return [ |
| 46 | 'og:', |
| 47 | 'twitter:', |
| 48 | 'viewport', |
| 49 | 'description', |
| 50 | 'keywords', |
| 51 | 'robots', |
| 52 | ].some( |
| 53 | (prefix) => attr.startsWith(prefix) || attr === prefix.slice(0, -1) |
| 54 | ) |
| 55 | }) |
| 56 | .map((el) => ({ |
| 57 | ...(el.name && { name: el.name }), |
| 58 | ...(el.hasAttribute('property') && { |
| 59 | property: el.getAttribute('property'), |
| 60 | }), |
| 61 | })) |
| 62 | .sort((a, b) => { |
| 63 | if (a.name && !b.name) return -1 |
| 64 | if (!a.name && b.name) return 1 |
| 65 | return (a.name || a.property || '').localeCompare( |
| 66 | b.name || b.property || '' |
| 67 | ) |
| 68 | }) |
| 69 | }) |
| 70 | return metas |
| 71 | } |
| 72 | |
| 73 | export async function getCommonMetadataHeadTags(browser: Playwright) { |
| 74 | const [links, metas] = await Promise.all([ |
no test coverage detected