-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoembed.js
29 lines (29 loc) · 862 Bytes
/
oembed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Message / communication between content_script and background_script
* used to get content from oEmbed APIs
* (cf: click-to-load.js, social.js)
*/
export function onMessageOEmbed(request, sender, sendResponse) {
if (request.message === 'oembed') {
// TODO cache oembed call
return fetch(request.options.oembedUrl, { cache: 'force-cache' })
.then((response) => {
if (!response || response.status !== 200) {
return true;
}
const logDone = (data) => {
return {
data: data,
tabId: sender.tab.id,
};
};
const logFail = (error) => {
console.warn('oembed error', error);
};
return response.json().then(logDone, logFail);
})
.catch(function (error) {
console.warn('oembed error', error);
});
}
}