I want to set a user-uploaded image as a wallpaper using the chrome.wallpaper api.
I managed to convert the uploaded file to an ArrayBuffer using JavaScript, but using that in the 'data' key resulted in an error message similar to this:
"Invalid value for argument 1. Property 'data': Expected 'binary' but got 'object'."
I converted the ArrayBuffer to a blob using new Blob(), but I got the same error. Converting it to a string resulted in the same error, but with 'object' replaced by 'string'.
Searching on Google has yielded nothing so far. What is the binary format in this case, and how would I send it?
The manifest definitely has the wallpaper attribute, and I was able to set the wallpaper through URLs as well. Binary is the only problem I'm facing.
The following is my code so far:
app.js:
reader.addEventListener('load', function() {
chrome.runtime.sendMessage({
'action': 'new_wallpaper',
'wallpaper_data': reader.result // I've also tried new Blob([reader.result])
}, function(response) {
console.log(response);
});
}, false);
reader.readAsArrayBuffer(file);
background.js:
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if(request.action == 'new_wallpaper') {
chrome.wallpaper.setWallpaper({
'data': request.wallpaper_data,
'layout': 'CENTER_CROPPED',
'filename': 'Wallpaper Manager',
'thumbnail': true
}, function(thumbnail) {
sendResponse(thumbnail);
});
}
return true;
});