bb-browser 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1656,6 +1656,9 @@ async function handleCommand(command) {
1656
1656
  case "trace":
1657
1657
  result = await handleTrace(command);
1658
1658
  break;
1659
+ case "history":
1660
+ result = await handleHistory(command);
1661
+ break;
1659
1662
  default:
1660
1663
  result = {
1661
1664
  id: command.id,
@@ -3136,6 +3139,83 @@ async function handleTrace(command) {
3136
3139
  };
3137
3140
  }
3138
3141
  }
3142
+ async function handleHistory(command) {
3143
+ const subCommand = command.historyCommand || "search";
3144
+ const days = typeof command.ms === "number" && command.ms > 0 ? command.ms : 30;
3145
+ const startTime = Date.now() - days * 24 * 60 * 60 * 1e3;
3146
+ console.log("[CommandHandler] History command:", subCommand, "days:", days);
3147
+ try {
3148
+ switch (subCommand) {
3149
+ case "search": {
3150
+ const items = await chrome.history.search({
3151
+ text: command.text || "",
3152
+ maxResults: command.maxResults || 100,
3153
+ startTime
3154
+ });
3155
+ return {
3156
+ id: command.id,
3157
+ success: true,
3158
+ data: {
3159
+ historyItems: items.map((item) => ({
3160
+ url: item.url || "",
3161
+ title: item.title || "",
3162
+ visitCount: item.visitCount || 0,
3163
+ lastVisitTime: item.lastVisitTime || 0
3164
+ }))
3165
+ }
3166
+ };
3167
+ }
3168
+ case "domains": {
3169
+ const items = await chrome.history.search({
3170
+ text: "",
3171
+ maxResults: 5e3,
3172
+ startTime
3173
+ });
3174
+ const domainMap = /* @__PURE__ */ new Map();
3175
+ for (const item of items) {
3176
+ if (!item.url) continue;
3177
+ let domain;
3178
+ try {
3179
+ domain = new URL(item.url).hostname;
3180
+ } catch {
3181
+ continue;
3182
+ }
3183
+ const current = domainMap.get(domain) || { visits: 0, titles: /* @__PURE__ */ new Set() };
3184
+ current.visits += item.visitCount || 0;
3185
+ if (item.title) {
3186
+ current.titles.add(item.title);
3187
+ }
3188
+ domainMap.set(domain, current);
3189
+ }
3190
+ const historyDomains = Array.from(domainMap.entries()).map(([domain, value]) => ({
3191
+ domain,
3192
+ visits: value.visits,
3193
+ titles: Array.from(value.titles)
3194
+ })).sort((a, b) => b.visits - a.visits);
3195
+ return {
3196
+ id: command.id,
3197
+ success: true,
3198
+ data: {
3199
+ historyDomains
3200
+ }
3201
+ };
3202
+ }
3203
+ default:
3204
+ return {
3205
+ id: command.id,
3206
+ success: false,
3207
+ error: `Unknown history subcommand: ${subCommand}`
3208
+ };
3209
+ }
3210
+ } catch (error) {
3211
+ console.error("[CommandHandler] History command failed:", error);
3212
+ return {
3213
+ id: command.id,
3214
+ success: false,
3215
+ error: `History command failed: ${error instanceof Error ? error.message : String(error)}`
3216
+ };
3217
+ }
3218
+ }
3139
3219
 
3140
3220
  const KEEPALIVE_ALARM = "bb-browser-keepalive";
3141
3221
  const sseClient = new SSEClient();