// Wrapper around chrome.runtime.sendMessage for native host communication. /** Send a typed message to the native host and return a Promise resolving to the response. */ function sendToNative(type, payload) { return new Promise((resolve) => { chrome.runtime.sendMessage( { target: 'holesail-native', action: 'send', payload: { type, payload } }, (response) => resolve(response) ); }); } /** Fetch the full extension state from the background service worker. */ async function fetchState() { return new Promise((resolve) => { chrome.runtime.sendMessage( { target: 'holesail-native', action: 'getState' }, (response) => { if (chrome.runtime.lastError) { log('fetchState error:', chrome.runtime.lastError.message); resolve(null); return; } if (response && response.ok) resolve(response.state); else resolve(null); } ); }); }