Is it possible to periodically write to a file?

184 views
Skip to first unread message

Nikita Vasilyev

unread,
Jul 22, 2023, 9:21:08 PM7/22/23
to Chromium Extensions
I want to implement daily local backups for my extension. I'll need to write to the same file once every 24 hours.

Is this even possible in MV3?

Doesn't work at all anymore.

Calling fileHandle.createWritable() from the background page throws an error:
"Uncaught DOMException: The request is not allowed by the user agent or the platform in the current context."

Is there any other way to periodically write to a file?


Nikita Vasilyev

unread,
Jul 22, 2023, 9:50:53 PM7/22/23
to Chromium Extensions, Nikita Vasilyev
The furthest I've come so far:

1. Ask user for the backup location using showSaveFilePicker.
2. Save the file handle in IndexedDB.
3. Every 24 hours, open an extension page that retrieves the file handle.
4. Call fileHandle.createWritable().
5. The user prompt is shown again, so we can't back up anything in the background :(
fs-prompt.png

(I could require one tab to be open at all times, but that's unacceptably bad UX.)

wOxxOm

unread,
Jul 23, 2023, 2:14:18 AM7/23/23
to Chromium Extensions, Nikita Vasilyev
Using FileSystem Access API will be possible in an extension when the following bugs are fixed: https://crbug.com/1359786https://crbug.com/1011533https://crbug.com/1445420. For now you'll have to 1) use an external application via nativeMessaging or 2) write the data to storage like IndexedDB or 3) download the data so the browser will put it in the default downloads directory, probably using DOM inside the offscreen document to avoid requesting the "downloads" permission.
Reply all
Reply to author
Forward
0 new messages