1
0
mirror of https://github.com/jiahaog/Nativefier synced 2024-06-26 07:38:59 +02:00
Nativefier/src/infer/inferTitle.js
Goh Jia Hao bd89f90a3d Remove workaround for slashes in page title
This was reported in #22 and has been fixed upstream in electron-userland/electron-packager#308
2018-06-10 11:00:22 -07:00

26 lines
594 B
JavaScript

import axios from 'axios';
import cheerio from 'cheerio';
const USER_AGENT =
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36';
function inferTitle(url) {
const options = {
method: 'get',
url,
headers: {
// fake a user agent because pages like http://messenger.com will throw 404 error
'User-Agent': USER_AGENT,
},
};
return axios(options).then(({ data }) => {
const $ = cheerio.load(data);
return $('title')
.first()
.text();
});
}
export default inferTitle;