Skip to content

Linux + iPhone Continuity / iMessage / SMS

Fix Chrome MV3 manifest and document local extension installation

David Boulayad8b6b0aca7d
diff --git a/README.md b/README.md
index 6246e52..fd8980e 100644
--- a/README.md
+++ b/README.md
@@ -81,6 +81,7 @@ The extension communicates with `tetherd` via native messaging. This allows user
### Browser Extension
- Firefox: [Tether Browser Extension](https://addons.mozilla.org/en-US/firefox/addon/tether-browser-extension/)
+- Google Chrome / Chromium: [Build and install locally](extension/README.md#local-chrome--chromium-installation).
### Mail Extension
- Thunderbird: [Tether Mail Extension](https://addons.thunderbird.net/en-US/thunderbird/addon/tether-mail-extension/)
diff --git a/extension/README.md b/extension/README.md
index cd81f75..2249be6 100644
--- a/extension/README.md
+++ b/extension/README.md
@@ -47,3 +47,32 @@ mkdir -p ~/.config/chromium/NativeMessagingHosts/
ln -s $(pwd)/build/com.tether.extension.chrome.json ~/.config/chromium/NativeMessagingHosts/com.tether.extension.json
```
+
+## Local Chrome / Chromium installation
+
+From the repository root, run `bash extension/build.sh` (Node.js, npm and zip
+are required). The Chrome build is written to `build/extension/chromium` and
+archived as `build/extension/tether-chromium-extension.zip`.
+
+1. Open `chrome://extensions` in the desired browser profile.
+2. Enable **Developer mode**, click **Load unpacked**, and select the absolute
+ path to `build/extension/chromium` in this checkout.
+3. Copy the extension ID displayed by the browser.
+4. With Tether installed, register the native host:
+
+ ```sh
+ python3 extension/host/install-chromium-host.py EXTENSION_ID
+ # For Chromium instead of Google Chrome:
+ python3 extension/host/install-chromium-host.py EXTENSION_ID --browser chromium
+ ```
+
+The helper finds `tether-native-host` on PATH. Use `--host /absolute/path` if
+installed elsewhere. It backs up an existing user registration and preserves
+its allowed extension origins. No sudo is needed. Reload the extension after
+registration. Tether's daemon must be running for OTP autofill.
+
+Load the extension separately in each desired profile. Keep the checkout at
+its current path, rebuild after updating it, then click **Reload** in the
+extensions page. This is an unpacked local installation, not a signed CRX or
+Chrome Web Store release. The extension ID can change if its path changes;
+rerun the helper with the new ID when necessary.
diff --git a/extension/build.sh b/extension/build.sh
index f7cb020..c880a0b 100755
--- a/extension/build.sh
+++ b/extension/build.sh
@@ -51,6 +51,15 @@ echo "Bundling Chromium extension..."
"$ESBUILD" extension/src/background/background.js --bundle --outfile="$CHROME_DIR/src/background/background.js"
"$ESBUILD" extension/src/content/autofill.js --bundle --outfile="$CHROME_DIR/src/content/autofill.js"
cp extension/manifest-browser.json "$CHROME_DIR/manifest.json"
+# Chrome MV3 uses a service worker; Firefox-only manifest fields are omitted.
+node --input-type=module - "$CHROME_DIR/manifest.json" <<'JS'
+import { readFileSync, writeFileSync } from 'node:fs';
+const path = process.argv[2];
+const manifest = JSON.parse(readFileSync(path, 'utf8'));
+delete manifest.browser_specific_settings;
+delete manifest.background.scripts;
+writeFileSync(path, JSON.stringify(manifest, null, 2) + '\n');
+JS
if [ -d "extension/icons" ]; then cp -R extension/icons "$CHROME_DIR/"; fi
make_archive "$CHROME_DIR" ../tether-chromium-extension.zip
diff --git a/extension/host/install-chromium-host.py b/extension/host/install-chromium-host.py
new file mode 100644
index 0000000..cd30e4d
--- /dev/null
+++ b/extension/host/install-chromium-host.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+"""Register an unpacked Chrome/Chromium extension with Tether (user scope)."""
+import argparse
+import datetime
+import json
+import os
+from pathlib import Path
+import re
+import shutil
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('extension_id')
+ parser.add_argument('--browser', choices=['chrome', 'chromium'], default='chrome')
+ parser.add_argument('--host', default=shutil.which('tether-native-host'))
+ args = parser.parse_args()
+ if not re.fullmatch('[a-p]{32}', args.extension_id):
+ parser.error('extension ID must contain 32 letters from a to p')
+ if not args.host or not Path(args.host).is_absolute():
+ parser.error('install tether-native-host or specify --host /absolute/path')
+ host = Path(args.host)
+ if not host.is_file() or not os.access(host, os.X_OK):
+ parser.error('native host must be an executable file')
+ browser = 'google-chrome' if args.browser == 'chrome' else 'chromium'
+ target = Path.home() / '.config' / browser / 'NativeMessagingHosts' / 'com.tether.extension.json'
+ origins = []
+ if target.exists():
+ previous = json.loads(target.read_text())
+ origins = previous.get('allowed_origins', [])
+ if not isinstance(origins, list) or not all(isinstance(x, str) for x in origins):
+ parser.error('existing allowed_origins must be a list of strings')
+ origin = f'chrome-extension://{args.extension_id}/'
+ if origin not in origins:
+ origins.append(origin)
+ manifest = dict(name='com.tether.extension', description='Tether Native Messaging Host',
+ path=str(host), type='stdio', allowed_origins=origins)
+ target.parent.mkdir(parents=True, exist_ok=True)
+ if target.exists():
+ stamp = datetime.datetime.now().strftime('%Y%m%d-%H%M%S-%f')
+ shutil.copy2(target, target.with_name(target.name + '.backup-' + stamp))
+ temporary = target.with_name(target.name + '.tmp')
+ temporary.write_text(json.dumps(manifest, indent=2) + '\n')
+ temporary.replace(target)
+ print(f'Registered {origin} in {target}')
+
+
+if __name__ == '__main__':
+ main()