Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Resolve absolute image URLs in request.fetchPublisherInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
diracdeltas committed Feb 13, 2018
1 parent e324721 commit 7e45c2b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/extensions/brave/content/scripts/requestHandler.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
const ipc = chrome.ipcRenderer

ipc.send('got-background-page-webcontents')
const parser = new DOMParser()

ipc.on('fetch-publisher-info', (e, url, options) => {
let finalUrl = url
window.fetch(url, options).then((response) => {
finalUrl = response.url
return response.text()
}).then((text) => {
const parser = new DOMParser()
const html = parser.parseFromString(text, 'text/html')
const image = html.querySelector('meta[property="og:image:secure_url"],meta[property="og:image:url"],meta[property="og:image"],meta[name="twitter:image:src"],meta[name="twitter:image"]').content
ipc.send('got-publisher-info-' + url, {
error: null,
url: finalUrl,
title: html.title,
image: html.querySelector('meta[property="og:image:secure_url"],meta[property="og:image:url"],meta[property="og:image"],meta[name="twitter:image:src"],meta[name="twitter:image"]').content
image: (new URL(image, finalUrl)).href
})
}).catch((err) => {
console.log('fetch error', err)
Expand Down
2 changes: 1 addition & 1 deletion js/lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module.exports.requestDataFile = (url, headers, path, reject, resolve) => {
* https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
* @param {string} url - url to fetch
* @param {Object} options - options to pass to window.fetch
* @param {Function(Object)} callback
* @param {Function({url: string, title: string, image: string, error: string})} callback
*/
module.exports.fetchPublisherInfo = (url, options, callback) => {
if (!backgroundPageWebContents) {
Expand Down

0 comments on commit 7e45c2b

Please sign in to comment.