fregante / webext-alert

alert() for background pages/workers in Web Extensions
https://webext-alert.vercel.app
MIT License
10 stars 0 forks source link

Expose callback utility to automatically show errors to the user #10

Open fregante opened 3 months ago

fregante commented 3 months ago

e.g.

chrome.action.onClicked.addListener(showErrors(() => {
    await chrome.permissions.request({origins: ['*://*/*']})
}))

would be equivalent to:

chrome.action.onClicked.addListener(() => {
    try {
        await chrome.permissions.request({origins: ['*://*/*']})
    } catch (error) {
        await webextAlert(error)
    }
});
fregante commented 3 months ago

See how ugly the try/catch looks for real code https://github.com/bfred-it/webext-domain-permission-toggle/blob/a803b62d76a2c0b2de7149bf336666fdcb644e3c/index.ts