I am using the message passing API and I'm successfully passing variables between popup and content script, but passing a file isn't working, it returns an empty value to the content script, instead of the file data.
What I already tried is:
Popup:
<input type="file" id="file">
$(document).on('change', '#file', function() {
var value = this.value;
var fileName = typeof value == 'string' ? value.match(/[^\/\\]+$/)[0] : value[0];
var fileData = this.files[0];
// this prints the file data successfully to console
console.log(fileData);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {action: "sendFile", file: fileData });
});
});
Content Script:
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
if (request.hasOwnProperty("action") && request.action == 'sendFile') {
console.log(file); // <-- empty
}
});
Is there any limitations in the messages API? or is there something I'm doing wrong?
Thanks.