This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add publishers media info request API
Needed for brave-intl/bat-publisher#11 (review) and #13114
- Loading branch information
1 parent
1f06bd2
commit 36173db
Showing
3 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const ipc = chrome.ipcRenderer | ||
|
||
ipc.send('got-background-page-webcontents') | ||
|
||
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') | ||
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 | ||
}) | ||
}).catch((err) => { | ||
console.log('fetch error', err) | ||
ipc.send('got-publisher-info-' + url, { | ||
url: finalUrl, | ||
error: err.message | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters