Awesome Open Source
Awesome Open Source

This package is no longer maintained, I had fun creating it and improving it but not interested in maintaining it and taking care of issues, if you need it fork it, release a copy, etc

Link Preview JS

Allows you to extract information from a HTTP url/link (or parse a HTML document) and retrieve meta information such as title, description, images, videos, etc. Written in Typescript. The information is extracted directly from the HTML from facebook OpenGraph protocol.


  • Browsers do not allow you to do requests to a different domain, you cannot request a different domain from your web app. If do not know how same-origin-policy works, here is a good intro, therefore this library works on node (back-end environments) and certain mobile run-times (cordova or react-native).
  • does not return a required meta data, test with another domain.
  • If you are running on a mobile, please think about what you are doing, this library does not do magic, it simply fetches the website and parses its html, therefore it acts as if the user would visit the page: YouTube re-directs you to the mobile site and Instagram (and other social sites) might redirect you to a sign up page, you can try to change the user-agent header (try with "google-bot"), but there is nothing wrong with this library, work around these issues yourself.

Created by Oscar Franco

Follow me on Twitter or please consider sponsoring to support the development.

How to use


yarn add link-preview-js
-- OR --
npm install link-preview-js


getLinkPreview: you have to pass a string, doesn't matter if it is just a URL or a piece of text that contains a URL, the library will take care of parsing it and returning the info of first valid HTTP(S) URL info it finds. (URL parsing is done via:

getPreviewFromContent: useful for passing a pre-fetched Response object from an existing async/etc. call. Refer to example below for required object values.

import { getLinkPreview, getPreviewFromContent } from 'link-preview-js';

// pass the link directly
  .then((data) => console.debug(data));

////////////////////////// OR //////////////////////////

// pass a chunk of text
getLinkPreview('This is a text supposed to be parsed and the first link displayed')
  .then((data) => console.debug(data));

////////////////////////// OR //////////////////////////

// pass a pre-fetched response object
// The passed response object should include, at minimum:
// {
//   data: '<!DOCTYPE...><html>...',     // response content
//   headers: {
//     ...
//     // should include content-type
//     content-type: "text/html; charset=ISO-8859-1",
//     ...
//   },
//   url: ''          // resolved url
// }
yourAjaxCall(url, (response) => {
    .then((data) => console.debug(data));


Additionally you can pass an options object which should add more functionality to the parsing of the link

Property Name Result
imagesPropertyType (optional) (ex: 'og') Fetches images only with the specified property, meta[property='${imagesPropertyType}:image']
headers (optional) (ex: { 'user-agent': 'googlebot', 'Accept-Language': 'en-US' }) Add request headers to fetch call
getLinkPreview("", {
  imagesPropertyType: "og", // fetches only open-graph images
  headers: {
    "user-agent": "googlebot" // fetches with googlebot crawler user agent
    "Accept-Language": "fr-CA", // fetches site for French language
    // ...other optional HTTP request headers
}).then(data => console.debug(data));


Returns a Promise that resolves with an object describing the provided link. The info object returned varies depending on the content type (MIME type) returned in the HTTP response (see below for variations of response). Rejects with an error if response can not be parsed or if there was no URL in the text provided.


  url: "",
  title: "OK Go - Needing/Getting - Official Video - YouTube",
  siteName: "YouTube",
  description: "Buy the video on iTunes: See more about the guitars at:",
  images: [""],
  mediaType: "video.other",
  contentType: "text/html; charset=utf-8",
  videos: [],

Image URL

  url: "",
  mediaType: "image",
  contentType: "image/jpeg",
  favicons: [ "" ]

Audio URL

  url: "",
  mediaType: "audio",
  contentType: "audio/mpeg",
  favicons: [ "" ]

Video URL

  url: "",
  mediaType: "video",
  contentType: "video/mp4",
  favicons: [ "" ]

Application URL

  url: "",
  mediaType: "application",
  contentType: "application/pdf",
  favicons: [ "" ]


MIT license

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
javascript (70,419
typescript (11,661
nodejs (3,811
react-native (1,542
http (931
chrome (465
firefox (316
parsing (190
extract (70
cors (52
safari (45
link (21
js-library (16