MCPcopy Index your code
hub / github.com/massCodeIO/massCode / captureFromTab

Function captureFromTab

integrations/clipper/src/background.ts:50–77  ·  view source on GitHub ↗
(
  tabId: number,
  target: CaptureTarget,
  context: { linkUrl?: string, selectionText?: string },
)

Source from the content-addressed store, hash-verified

48})
49
50async function captureFromTab(
51 tabId: number,
52 target: CaptureTarget,
53 context: { linkUrl?: string, selectionText?: string },
54): Promise<void> {
55 try {
56 const settings = await getSettings()
57 if (!settings.apiToken.trim()) {
58 throw new Error('Set the massCode API token in the extension popup.')
59 }
60
61 const payload = await getPageCapture(tabId)
62 const request = buildCaptureRequest(target, {
63 ...payload,
64 selectedText: payload.selectedText || context.selectionText?.trim() || '',
65 url: context.linkUrl || payload.url,
66 })
67
68 const result = await postCapture(settings, request)
69 await notify(
70 'Saved to massCode',
71 `Created ${result.target} item #${result.id}.`,
72 )
73 }
74 catch (error) {
75 await notify('massCode capture failed', getErrorMessage(error))
76 }
77}
78
79async function getPageCapture(tabId: number): Promise<PageCapturePayload> {
80 const [response] = await chrome.scripting.executeScript<PageCapturePayload>({

Callers 1

background.tsFile · 0.85

Calls 6

getSettingsFunction · 0.90
buildCaptureRequestFunction · 0.90
postCaptureFunction · 0.90
getPageCaptureFunction · 0.85
notifyFunction · 0.85
getErrorMessageFunction · 0.70

Tested by

no test coverage detected