Tim Pillard
unread,Aug 29, 2025, 11:03:02 AM (7 days ago) Aug 29Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Chromium Extensions
Hi,
Our Extension checks for some permissions in the manifest during its service worker critical initialization code path.
We have noticed in our reported exceptions something odd, it seems sometimes (up to a few hundred times per day) chrome.runtime.getManifest is either missing some keys or values, or the chrome namespace is missing properties.
Consider the following code which we use to determine whether or not we should use declarativeNetRequest (MV3) or WebRequest Blocking (MV2):
```ts
// manifest.json
// {
// permissions: ['declarativeNetRequest']
// }
function isApiAvailable(path: string): boolean {
if (typeof chrome === 'undefined') {
return false;
}
const pathList = path.split('.');
const api = pathList.reduce(
(memo: any, subPath: string) => memo?.[subPath],
chrome,
);
return Boolean(api);
}
function hasPermissions(requiredPermissions: string[]): boolean {
const permissions = chrome.runtime.getManifest().permissions ?? [];
return requiredPermissions.every((permission) =>
permissions.includes(permission),
);
}
// {...}
if (
isApiAvailable('declarativeNetRequest') &&
hasPermissions(['declarativeNetRequest'])
) {
// This code path is not entered.
} else {
// This code path is entered.
// {...}
console.log(getManifest().permissions);
// ['declarativeNetRequest']
}
// {...}
```
Our Extension sees declarativeNetRequest as not supported and enters the WebRequest Blocking code path, which fails.
Is anyone seeing something similar?