My goal is to upload a file in the background task with a file coming from the content script.
I figured it's not possible to pass a File object directly from content script to the background because chrome.runtime.sendMessage
JSON serialize the data.
It's possible to pass a string url to the file with URL.createObjectURL
, which works. But the URL is tied to the document in the window on which it was created (current tab content script). If I refresh, navigates away, close the tab those urls are destroyed.
Read the entire file with FileReader and keep in memory is not an option because it'll crash the extension on large files.
Questions:
- Keep the
URL.createObjectURL
alive? - Pass File object to background?
- Upload a file in the background task with a file from the content script?
- Pass file link to popup and submit form there, which then run in background?