Overview
I'm writing a ChromeOS Files extension for encrypting files. For that I'm using the Google Chrome chrome.fileBrowserHandler API. When opening the Files context menu, I get an "Encrypt" option (Open with… > Encrypt):
The issue I'm facing
The example code snipped provided by the API documentation does throw an Uncaught TypeError.
The error message written for accessibility:
// Warning: Service worker registration failed. Status code: 15
"service_worker": "background.js"
// Error: Uncaught TypeError: Cannot read properties of undefined (reading 'onExecute')
// Context
// background.js
// Stack Trace
// background.js:3 (anonymous function)
chrome.fileBrowserHandler.onExecute.addListener((id, details) => {
Why am I facing the error message?
Source Code
// background.js
"use strict";
chrome.fileBrowserHandler.onExecute.addListener((id, details) => {
if (id === "encrypt") {
chrome.windows.create({
url: chrome.runtime.getURL('popup.html'),
type: "popup"
});
}
});
// manifest.json
{
"manifest_version": 3,
"name": "Encrypt My Files",
"description": "Encrypt files natively on ChromeOS",
"version": "0.1.0",
"permissions": ["fileBrowserHandler"],
"background": {
"service_worker": "background.js"
},
"action": {
"default_popup": "popup.html"
},
"file_browser_handlers": [
{
"id": "encrypt",
"default_title": "Encrypt",
"file_filters": [
"filesystem:*.*"
]
}
],
"minimum_chrome_version": "120"
}
Things I noticed
When specifying just a console.log statement in background.js, the extension can be turned on without any issues. Also, using a chrome.runtime.onInstalled.addListener in background.js (e.g. for context menus in web pages) works.

