diff --git a/src/fpd/enrichment.ts b/src/fpd/enrichment.ts index 005522dec9..07e2d5373c 100644 --- a/src/fpd/enrichment.ts +++ b/src/fpd/enrichment.ts @@ -201,7 +201,7 @@ function collectJsonLdKeywords(node, keywords: string[], depth = 0) { export const getJsonLdKeywords = memoize(() => { return winFallback((win) => { const keywords: string[] = []; - win.document.querySelectorAll('script[type="application/ld+json"]').forEach(scriptTag => { + Array.from(win.document.querySelectorAll('script[type="application/ld+json"]')).forEach((scriptTag: HTMLScriptElement) => { try { collectJsonLdKeywords(JSON.parse(scriptTag.textContent), keywords); } catch (e) { @@ -215,8 +215,8 @@ export const getJsonLdKeywords = memoize(() => { export const getMetaTagKeywords = memoize(() => { return winFallback((win) => { const keywords: string[] = []; - win.document.querySelectorAll('meta[name="keywords"], meta[name="news_keywords"], meta[property="article:tag"]') - .forEach(tag => keywords.push(...tag.content.split(','))); + Array.from(win.document.querySelectorAll('meta[name="keywords"], meta[name="news_keywords"], meta[property="article:tag"]')) + .forEach((tag: HTMLMetaElement) => keywords.push(...tag.content.split(','))); return keywords; }); }); diff --git a/test/spec/fpd/enrichment_spec.js b/test/spec/fpd/enrichment_spec.js index bbe66db504..55b0a6b230 100644 --- a/test/spec/fpd/enrichment_spec.js +++ b/test/spec/fpd/enrichment_spec.js @@ -138,6 +138,13 @@ describe('FPD enrichment', () => { }); }); + it('sets keywords in browsers without NodeList.prototype.forEach (Chrome 50)', () => { + sandbox.stub(NodeList.prototype, 'forEach').value(undefined); + addMetaKeywords(['kw1']); + addJsonKeywords(['kw2']); + return expectKeywords('kw1,kw2'); + }); + it('should not use meta tag if firstPartyData.keywords.meta is false', () => { config.setConfig({ firstPartyData: {