browser.browserAction.onClicked.addListener(()=>browser.runtime.openOptionsPage()); async function handleMessage(request) { if (request.magnet) { const opts = await browser.storage.local.get(); if (!opts.enabled) return new Promise((r,e) => e(new Error("Extension is not enabled"))); return fetch(opts.url, { method: 'POST', body: JSON.stringify({url: request.magnet}) }).then(res => res.text()).then(text => { if (text === 'OK') return text; return new Promise((r,e) => e(new Error(text))); }); } } browser.runtime.onMessage.addListener(handleMessage);