summaryrefslogtreecommitdiff
path: root/crumb_extension/background.js
blob: c916c95cc8ce83d5578ae056a1414d69044b552f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
  if (changeInfo.status !== 'complete' || !tab.url.startsWith("http")) return;

  const url = new URL(tab.url);

  const payload = {
    title: tab.title,
    url: tab.url,
    hostname: url.hostname,
    path: url.pathname,
    query: url.search,
    tabId: tab.id,
    windowId: tab.windowId,
    favIconUrl: tab.favIconUrl || null
  };

  console.log("Crumb: Sending payload", payload);

  fetch("http://localhost:3555", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(payload)
  }).catch(err => {
    console.error("Crumb: Failed to reach server", err);
  });
});