chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { url = message.url; action = message.action; console.log({ url, action }); if (action === 'save') { fetch(`https://pod.gregoryleeman.com/add?url=${encodeURIComponent(url)}`, { method: 'GET', headers: { 'Content-Type': 'application/json' } }) .then((response) => response.json()) .then((data) => { console.log({ data }); sendResponse({ success: true, data }); }) .catch((error) => { console.error({ error }); sendResponse({ success: false, error }); }); return true; } else if ( action == 'check' ) { fetch(`https://pod.gregoryleeman.com/check?url=${encodeURIComponent(url)}`, { method: 'GET', headers: { 'Content-Type': 'application/json' } }) .then((response) => response.json()) .then((data) => { console.log({ data }); sendResponse({ success: true, data }); }) .catch((error) => { console.error({ error }); sendResponse({ success: false, error }); }); return true; } else { sendResponse({ success: false, error: 'Invalid action' }); } });