Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions browser-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Start a Deep Sesh or Pomodoro session before testing browser activity.
3. Click Load unpacked.
4. Select the project `browser-extension` folder.
5. Start a Taskmaster focus session, then switch tabs.
6. Native Messaging requires a host install step that will be added in the next phase.
6. Install the native host using the steps below.

## Load In Opera GX

Expand All @@ -50,9 +50,24 @@ Start a Deep Sesh or Pomodoro session before testing browser activity.
5. Stop the Taskmaster session.
6. Switch browser tabs again and confirm the panel no longer receives new activity.

## Install Native Messaging Host

From the project root:

```powershell
.\native-host\install-chrome-native-host.ps1
```

This registers the host under the current Windows user:

```txt
HKCU\Software\Google\Chrome\NativeMessagingHosts\com.taskmaster.browser_monitor
```

Restart Chrome after installing the host.

## Current Limitations

- Native Messaging host setup is not implemented yet.
- It only reports the active tab in the focused browser window.
- It does not classify, block, notify, or persist browsing activity.
- Internal browser pages such as `chrome://`, `edge://`, `opera://`, `about:`, and `devtools://` are ignored.
Expand All @@ -76,6 +91,12 @@ The package includes only:
- `manifest.json`
- `background.js`

## Future Production Plan
## Native Messaging

The extension uses:

```txt
com.taskmaster.browser_monitor
```

The next phase will add the Native Messaging host and install scripts.
The native host forwards validated messages to the local Taskmaster desktop app on the same device.
9 changes: 5 additions & 4 deletions browser-extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// - Page content, cookies, form inputs, and the browsing history API are never read.
// - The active tab URL/title is queried only after Taskmaster says monitoring is active.
//
// Transport is intentionally separated from tab collection so the same privacy
// gate can work with the current dev localhost bridge and future Native Messaging.
// Transport is intentionally separated from tab collection. Production uses
// Native Messaging; the old localhost path is retained only for local debugging.

const BRIDGE_ORIGIN = 'http://127.0.0.1:17382'
const STATUS_URL = `${BRIDGE_ORIGIN}/taskmaster-browser-monitor/status`
Expand Down Expand Up @@ -91,7 +91,8 @@ async function isMonitoringEnabled() {
return isDevLocalhostMonitoringEnabled()
}

// Placeholder production status check. Phase 2 will wire this to the native host.
// Production status check. Chrome launches the registered Native Messaging host,
// then the host asks the local Taskmaster bridge whether monitoring is active.
async function isNativeMonitoringEnabled() {
try {
const response = await chrome.runtime.sendNativeMessage(NATIVE_HOST_NAME, {
Expand Down Expand Up @@ -156,7 +157,7 @@ async function sendActivity(payload) {
await sendDevLocalhostActivity(payload)
}

// Placeholder production sender. Phase 2 will add the native host implementation.
// Production sender. The native host validates and forwards this to Taskmaster.
async function sendNativeActivity(payload) {
try {
await chrome.runtime.sendNativeMessage(NATIVE_HOST_NAME, {
Expand Down
11 changes: 6 additions & 5 deletions electron/src/main/browser-activity-bridge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Dev-only localhost bridge for the Taskmaster browser extension prototype.
// This accepts active tab metadata only while a focus session has enabled monitoring.
// Local Taskmaster app bridge for browser activity messages.
// Native Messaging host forwards validated active-tab metadata here while a
// focus session has enabled monitoring.

import http from 'node:http'
import type { BrowserActivityPayload } from '../shared/browserActivity.ts'
Expand All @@ -16,7 +17,7 @@ let isBrowserMonitoringActive = false
let latestBrowserActivity: BrowserActivityPayload | null = null
let notifyRenderer: BrowserActivityListener | null = null

/* Starts the dev HTTP bridge once the Electron app is ready. */
/* Starts the local HTTP bridge once the Electron app is ready. */
export function startBrowserActivityBridge(onActivity: BrowserActivityListener) {
notifyRenderer = onActivity

Expand Down Expand Up @@ -57,7 +58,7 @@ export function startBrowserActivityBridge(onActivity: BrowserActivityListener)
})
}

/* Closes the local bridge during app shutdown. */
/* Closes the local app bridge during app shutdown. */
export function stopBrowserActivityBridge() {
setBrowserMonitoringActive(false)

Expand Down Expand Up @@ -186,7 +187,7 @@ function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null
}

/* Allows the unpacked dev extension to call the local bridge during development. */
/* Allows local development and the native host to call the app bridge. */
function addCorsHeaders(response: http.ServerResponse) {
response.setHeader('Access-Control-Allow-Origin', '*')
response.setHeader('Access-Control-Allow-Methods', 'GET,POST,OPTIONS')
Expand Down
2 changes: 2 additions & 0 deletions native-host/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore machine-specific launchers/manifests generated by the native host installer.
.generated/
69 changes: 69 additions & 0 deletions native-host/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Taskmaster Browser Monitor Native Host

This folder contains the Chrome Native Messaging host for the Taskmaster Browser Monitor extension.

The extension talks to this host through Chrome Native Messaging. The host then forwards validated messages to the local Taskmaster desktop app bridge on `127.0.0.1:17382`.

The extension itself does not require localhost host permissions.

## Host Name

```txt
com.taskmaster.browser_monitor
```

## Allowed Chrome Extension

```txt
kibldolnfbpajohdnkbjfjefnemllapm
```

## Install On Windows

From the repo root:

```powershell
.\native-host\install-chrome-native-host.ps1
```

This registers the host under:

```txt
HKCU\Software\Google\Chrome\NativeMessagingHosts\com.taskmaster.browser_monitor
```

HKCU is used so admin rights are not required.

## Verify Registration

1. Open `regedit`.
2. Go to:
```txt
HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\com.taskmaster.browser_monitor
```
3. Confirm the default value points to the generated manifest in:
```txt
native-host\.generated\com.taskmaster.browser_monitor.chrome.json
```

## Test Flow

1. Install the native host.
2. Start Taskmaster Electron dev.
3. Load or install the Chrome extension with ID `kibldolnfbpajohdnkbjfjefnemllapm`.
4. Start a Deep Sesh or Pomodoro session.
5. Open GitHub, YouTube, or ChatGPT.
6. Confirm FocusMonitorPanel shows the current domain and title.
7. Stop the focus session and confirm tab updates stop.

## Debugging

If Chrome says the native host was not found:

- Confirm the registry key exists under HKCU, not HKLM.
- Confirm the manifest path in the registry exists.
- Confirm the generated manifest `path` points to the generated `.cmd` launcher.
- Confirm `node` is installed and available when running the install script.
- Restart Chrome after installing the native host.

Raw URLs are not logged by default.
9 changes: 9 additions & 0 deletions native-host/com.taskmaster.browser_monitor.chrome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "com.taskmaster.browser_monitor",
"description": "Taskmaster Browser Monitor Native Host",
"path": "ABSOLUTE_PATH_CREATED_BY_install-chrome-native-host.ps1",
"type": "stdio",
"allowed_origins": [
"chrome-extension://kibldolnfbpajohdnkbjfjefnemllapm/"
]
}
41 changes: 41 additions & 0 deletions native-host/install-chrome-native-host.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Registers the Taskmaster Browser Monitor native host for Chrome under HKCU.
# This does not require admin rights and writes a generated local manifest.

$ErrorActionPreference = "Stop"

$hostName = "com.taskmaster.browser_monitor"
$nativeHostDir = $PSScriptRoot
$generatedDir = Join-Path $nativeHostDir ".generated"
$generatedManifestPath = Join-Path $generatedDir "$hostName.chrome.json"
$generatedLauncherPath = Join-Path $generatedDir "taskmaster-browser-monitor-host.cmd"
$hostScriptPath = Join-Path $nativeHostDir "taskmaster-browser-monitor-host.js"
$nodePath = (Get-Command node -ErrorAction Stop).Source
$registryPath = "HKCU:\Software\Google\Chrome\NativeMessagingHosts\$hostName"

New-Item -ItemType Directory -Path $generatedDir -Force | Out-Null

$launcherContent = @"
@echo off
"$nodePath" "$hostScriptPath"
"@

Set-Content -LiteralPath $generatedLauncherPath -Value $launcherContent -Encoding ASCII

$manifest = @{
name = $hostName
description = "Taskmaster Browser Monitor Native Host"
path = $generatedLauncherPath
type = "stdio"
allowed_origins = @(
"chrome-extension://kibldolnfbpajohdnkbjfjefnemllapm/"
)
}

$manifest | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath $generatedManifestPath -Encoding UTF8

New-Item -Path $registryPath -Force | Out-Null
Set-Item -Path $registryPath -Value $generatedManifestPath

Write-Host "Registered $hostName"
Write-Host "Manifest: $generatedManifestPath"
Write-Host "Registry: $registryPath"
Loading
Loading