replacement for URL.createObjectURL(blob);

2,332 views
Skip to first unread message

joette cordsen

unread,
Sep 20, 2021, 7:45:55 PM9/20/21
to Chromium Extensions
I have a background process that takes a backup of some user data and uses this to create a URL and then uses chrome.downloads.download to download the backup to the users drive. I am converting this extension to use manifest V3, and since there is no DOM this doesn't work. The blob is one big string.

Does anyone have an easy replacement/example to share of another way to do this download? I could have the content script that kicks off the process for the download do the backup, but I really would rather not, because it is something that the background determines needs to be done. btw - users do have control over whether this automatic backup even happens. Its an option they set once, and then the backup is a daily thing. 

Thx

wOxxOm

unread,
Sep 21, 2021, 10:33:15 AM9/21/21
to Chromium Extensions, jill...@gmail.com
There's no direct replacement in ManifestV3.
This is yet another inherent problem of service workers, a technology that exists for an entirely different use case.

Some workarounds:
  1. generate a data URI which should be shorter than 64MB:
    chrome.downloads.download({url: 'data:application/json;base64,' + btoa(JSON.stringify(data)), filename: 'file.json'})

  2. open a new window where you can use URL.createObjectURL.
In the future a possible solution might be for chrome.downloads API to accept a Blob/ArrayBuffer directly: https://crbug.com/1224027. Another possible solution would be when nested workers are allowed, https://crbug.com/1219164, so the service worker would start a normal web worker which will create a Blob URL, then pass it back to the service worker via navigator.serviceWorker messaging or BroadcastChannel.

Christoph142

unread,
Jun 17, 2023, 6:00:19 PM6/17/23
to Chromium Extensions, wOxxOm, jill...@gmail.com
For anyone stumbling upon this question: https://developer.chrome.com/blog/Offscreen-Documents-in-Manifest-v3/ should be the (interim) solution.
Reply all
Reply to author
Forward
0 new messages