- add Chrome/Chromium Manifest V3 build with PAC proxy routing - keep Firefox Manifest V2 and Android compatibility - add Chromium API adapter and service worker - add Chrome build script and Makefile target - update README and add AGENT.md - document installation, signing, permissions, themes, and platform limitations
32 lines
955 B
JavaScript
32 lines
955 B
JavaScript
// Small Promise-based WebExtension API adapter for Chromium browsers.
|
|
// Firefox already provides the browser namespace, so this is a no-op there.
|
|
(function () {
|
|
if (globalThis.browser || !globalThis.chrome) return;
|
|
|
|
const wrap = (object, method) => (...args) => new Promise((resolve, reject) => {
|
|
object[method](...args, result => {
|
|
const error = globalThis.chrome.runtime.lastError;
|
|
if (error) reject(new Error(error.message));
|
|
else resolve(result);
|
|
});
|
|
});
|
|
|
|
globalThis.browser = {
|
|
runtime: {
|
|
sendMessage: wrap(chrome.runtime, 'sendMessage'),
|
|
openOptionsPage: wrap(chrome.runtime, 'openOptionsPage'),
|
|
onMessage: chrome.runtime.onMessage
|
|
},
|
|
tabs: {
|
|
query: wrap(chrome.tabs, 'query'),
|
|
reload: wrap(chrome.tabs, 'reload')
|
|
},
|
|
storage: {
|
|
local: {
|
|
get: wrap(chrome.storage.local, 'get'),
|
|
set: wrap(chrome.storage.local, 'set')
|
|
}
|
|
}
|
|
};
|
|
})();
|