| 166 | } |
| 167 | |
| 168 | async function getActiveTabCapture(): Promise<PageCapturePayload> { |
| 169 | const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }) |
| 170 | |
| 171 | if (!tab.id) { |
| 172 | throw new Error('No active tab found.') |
| 173 | } |
| 174 | |
| 175 | const [response] = await chrome.scripting.executeScript<PageCapturePayload>({ |
| 176 | func: getPageCaptureFromPage, |
| 177 | target: { tabId: tab.id }, |
| 178 | }) |
| 179 | |
| 180 | if (!response.result) { |
| 181 | throw new Error('Could not read the active page.') |
| 182 | } |
| 183 | |
| 184 | return { |
| 185 | ...response.result, |
| 186 | faviconUrl: tab.favIconUrl, |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | function readSettingsFromForm(): ExtensionSettings { |
| 191 | return { |