SQLite and OPFS not working in Firefox extension

Hi,

I’m using Firefox nightly and trying to create an extension using SQLite and OPFS. When I go to this URL in Firefox, I see the message “The OPFS is available.”.

When I convert that same example into an extension, and load it in Firefox nightly via web-ext, I get a message that OPFS is not supported.

In my manifest.json, I have the following lines:

"cross_origin_embedder_policy": {
    "value": "require-corp"
},
"cross_origin_opener_policy": {
    "value": "same-origin"
},
"content_security_policy": {
    "extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self';"
}

The COEP/COOP entries are supported in Chrome’s manifest.json since Chrome v93, but I don’t see any mention of them in Firefox’s documentation.

Is there some other way of specifying COEP/COOP for a Firefox extension?

Thanks

2 Likes

@randy I’m currently also considering using sqlite/OPFS in a FF extension. Are you still experiencing this issue now that 111.0 was officially released with OPFS support? If so maybe we should raise it on Bugzilla.

@djahandarie, thanks for the reply! Yes, I still have the same issue using Firefox 111.0 and the official build of sqlite-wasm v3.41.

The problem still seems to be that Firefox doesn’t recognize the COOP/COEP keys in the manifest.json file, and I don’t know how else to specify those headers in an extension.

Where is the proper place to report this? I’m unfamiliar with Firefox development.

Thanks for double checking! A couple thoughts:

  • The reason these headers are required for sqlite/OPFS is because they use SharedArrayBuffer, which requires them. (ref 1, ref 2)
  • However, in Chrome extensions, SharedArrayBuffer works without those headers, so sqlite/OPFS are usable. (ref)
  • Unrelated to OPFS, there was an issue on the Firefox bug tracker regarding SharedArrayBuffer usage within extensions two years ago, which culminated in only allowing it for privileged extensions (aka not available to normal people like us). (ref)

I think it’d be worth raising another bug on bugzilla.mozilla.org specifically about OPFS usage within extensions, while linking to the above bug and context. Would you like to give that a shot?

2 Likes

Feel free to add any other info you think is appropriate.

2 Likes