Gathering detailed insights and metrics for open-graph-scraper
Gathering detailed insights and metrics for open-graph-scraper
Gathering detailed insights and metrics for open-graph-scraper
Gathering detailed insights and metrics for open-graph-scraper
@types/open-graph-scraper
TypeScript definitions for open-graph-scraper
open-graph-scraper-lite
Javascript scraper module for Open Graph and Twitter Card info
metadata-scraper
A Javascript library for scraping/parsing metadata from a web page.
react-native-open-graph-scraper
React Native scraper module for Open Graph and Twitter Card info
Node.js scraper service for Open Graph Info and More!
npm install open-graph-scraper
Typescript
Module System
Min. Node Version
Node Version
NPM Version
97.5
Supply Chain
98.1
Quality
87.5
Maintenance
100
Vulnerability
100
License
TypeScript (99.82%)
JavaScript (0.12%)
Dockerfile (0.06%)
Total Downloads
11,043,783
Last Day
12,697
Last Week
70,266
Last Month
295,442
Last Year
3,157,844
MIT License
699 Stars
1,214 Commits
109 Forks
8 Watchers
3 Branches
41 Contributors
Updated on May 06, 2025
Latest Version
6.10.0
Package Id
open-graph-scraper@6.10.0
Unpacked Size
185.08 kB
Size
26.13 kB
File Count
35
NPM Version
9.8.1
Node Version
18.18.0
Published on
Apr 21, 2025
Cumulative downloads
Total Downloads
Last Day
28.6%
12,697
Compared to previous day
Last Week
7.7%
70,266
Compared to previous week
Last Month
6%
295,442
Compared to previous month
Last Year
8.2%
3,157,844
Compared to previous year
4
A simple node module(with TypeScript declarations) for scraping Open Graph and Twitter Card and other metadata off a site.
Note: open-graph-scraper
doesn't support browser usage at this time but you can use open-graph-scraper-lite
if you already have the HTML
and can't use Node's Fetch API.
1npm install open-graph-scraper --save
1const ogs = require('open-graph-scraper'); 2const options = { url: 'http://ogp.me/' }; 3ogs(options) 4 .then((data) => { 5 const { error, html, result, response } = data; 6 console.log('error:', error); // This returns true or false. True if there was an error. The error itself is inside the result object. 7 console.log('html:', html); // This contains the HTML of page 8 console.log('result:', result); // This contains all of the Open Graph results 9 console.log('response:', response); // This contains response from the Fetch API 10 })
Check the return for a success
flag. If success is set to true, then the url input was valid. Otherwise it will be set to false. The above example will return something like...
1{ 2 ogTitle: 'Open Graph protocol', 3 ogType: 'website', 4 ogUrl: 'https://ogp.me/', 5 ogDescription: 'The Open Graph protocol enables any web page to become a rich object in a social graph.', 6 ogImage: [ 7 { 8 height: '300', 9 type: 'image/png', 10 url: 'https://ogp.me/logo.png', 11 width: '300' 12 } 13 ], 14 charset: 'utf-8', 15 requestUrl: 'http://ogp.me/', 16 success: true 17}
Name | Info | Default Value | Required |
---|---|---|---|
url | URL of the site. | x | |
html | You can pass in an HTML string to run ogs on it. (use without options.url) | ||
fetchOptions | Options that are used by the Fetch API | {} | |
timeout | Request timeout for Fetch (Default is 10 seconds) | 10 | |
blacklist | Pass in an array of sites you don't want ogs to run on. | [] | |
onlyGetOpenGraphInfo | Only fetch open graph info and don't fall back on anything else. Also accepts an array of properties for which no fallback should be used | false | |
customMetaTags | Here you can define custom meta tags you want to scrape. | [] | |
urlValidatorSettings | Sets the options used by validator.js for testing the URL | Here | |
jsonLDOptions | Sets the options used when parsing JSON-LD data |
Note: open-graph-scraper
uses the Fetch API for requests and most of Fetch's options should work as open-graph-scraper
's fetchOptions
options.
1// example of how to get types 2import type { SuccessResult } from 'open-graph-scraper/types'; 3const example: SuccessResult = { 4 result: { ogTitle: 'this is a title' }, 5 error: false, 6 response: {}, 7 html: '<html></html>' 8} 9 10// import example 11import ogs from 'open-graph-scraper'; 12const options = { url: 'http://ogp.me/' }; 13ogs(options) 14 .then((data) => { 15 const { error, html, result, response } = data; 16 console.log('error:', error); // This returns true or false. True if there was an error. The error itself is inside the result object. 17 console.log('html:', html); // This contains the HTML of page 18 console.log('result:', result); // This contains all of the Open Graph results 19 console.log('response:', response); // This contains response from the Fetch API 20 });
1const ogs = require('open-graph-scraper'); 2const options = { 3 url: 'https://github.com/jshemas/openGraphScraper', 4 customMetaTags: [{ 5 multiple: false, // is there more than one of these tags on a page (normally this is false) 6 property: 'hostname', // meta tag name/property attribute 7 fieldName: 'hostnameMetaTag', // name of the result variable 8 }], 9}; 10ogs(options) 11 .then((data) => { 12 const { result } = data; 13 console.log('hostnameMetaTag:', result.customMetaTags.hostnameMetaTag); // hostnameMetaTag: github.com 14 })
1const ogs = require('open-graph-scraper'); 2const options = { 3 html: `<html><head> 4 <link rel="icon" type="image/png" href="https://bar.com/foo.png" /> 5 <meta charset="utf-8" /> 6 <meta property="og:description" name="og:description" content="html description example" /> 7 <meta property="og:image" name="og:image" content="https://www.foo.com/bar.jpg" /> 8 <meta property="og:title" name="og:title" content="foobar" /> 9 <meta property="og:type" name="og:type" content="website" /> 10 </head></html>` 11}; 12ogs(options) 13 .then((data) => { 14 const { result } = data; 15 console.log('result:', result); 16 // result: { 17 // ogDescription: 'html description example', 18 // ogTitle: 'foobar', 19 // ogType: 'website', 20 // ogImage: [ { url: 'https://www.foo.com/bar.jpg', type: 'jpg' } ], 21 // favicon: 'https://bar.com/foo.png', 22 // charset: 'utf-8', 23 // success: true 24 // } 25 }) 26
The request header is set to undici by default. Some sites might block this, and changing the userAgent
might work. If not you can try using a proxy for the request and then pass the html
into open-graph-scraper
.
1const ogs = require("open-graph-scraper"); 2const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36'; 3ogs({ url: 'https://www.wikipedia.org/', fetchOptions: { headers: { 'user-agent': userAgent } } }) 4 .then((data) => { 5 const { error, html, result, response } = data; 6 console.log('error:', error); // This returns true or false. True if there was an error. The error itself is inside the result object. 7 console.log('html:', html); // This contains the HTML of page 8 console.log('result:', result); // This contains all of the Open Graph results 9 console.log('response:', response); // This contains response from the Fetch API 10 })
throwOnJSONParseError
and logOnJSONParseError
properties control what happens if JSON.parse
throws an error when parsing JSON-LD data.
If throwOnJSONParseError
is set to true
, then the error will be thrown.
If logOnJSONParseError
is set to true
, then the error will be logged to the console.
1const ogs = require("open-graph-scraper"); 2const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36'; 3ogs({ url: 'https://www.wikipedia.org/', jsonLDOptions: { throwOnJSONParseError: true } }) 4 .then((data) => { 5 const { error, html, result, response } = data; 6 console.log('error:', error); // This returns true or false. True if there was an error. The error itself is inside the result object. 7 console.log('html:', html); // This contains the HTML of page 8 console.log('result:', result); // This contains all of the Open Graph results 9 console.log('response:', response); // This contains response from the Fetch API 10 })
Inside the example
folder contains a simple express app where you can run npm ci && npm run start
to spin up. Once the app is running, open a web browser and go to http://localhost:3000/scraper?url=http://ogp.me/
to test it out. There is also a Dockerfile
if you want to run this example app in a docker container.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
SAST tool is not run on all commits -- score normalized to 5
Details
Reason
Found 3/14 approved changesets -- score normalized to 2
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More