I'm learning JavaScript and I decided to make a Chrome extension that will take a screenshot and send it to a notion page. I make the screenshot from thee background.js and send it to the content.js:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.message === 'capture')
chrome.tabs.captureVisibleTab(
null,
{},
function(dataUrl)
{
sendResponse({imgSrc:dataUrl});
}
);
return true;
});
The problem is that to send the image to notion using the notion API I need the URL of the image; how can I get that url? Is there any way I can convert that screenshot to a URL and be able to send it?
I tried to send the dataURL received by the background.js but it gives me back an error:
const options = {
method: 'PATCH',
headers: {
accept: 'application/json',
'Notion-Version': '2022-06-28',
'content-type': 'application/json',
'Authorization': 'Bearer ' + token.access_token
},
body: JSON.stringify({
"children": [{
'type': 'image',
'image': {
"caption": [],
'type': 'external',
'external': {
'url': image_url
}
}
}]})
};
fetch(`https://api.notion.com/v1/blocks/${page.id}/children`,
options
)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
}