1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 * Collects Twitter card (https://developer.twitter.com/en/docs/twitter-for-websites/)
7 * related data from a page.
9 export const TwitterPageData = {
11 * Collects the twitter data from the page.
13 * @param {Document} document
14 * The document to collect from
21 let twitterTags = document.querySelectorAll("meta[name^='twitter:'");
23 for (let tag of twitterTags) {
24 // Strip "twitter:" from the property name.
25 let propertyName = tag.getAttribute("name").substring(8);
27 switch (propertyName) {
29 pageData.siteName = tag.getAttribute("content");
32 pageData.description = tag.getAttribute("content");
35 pageData.image = tag.getAttribute("content");