termweb 0.9.2 → 0.9.5

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.
Files changed (3) hide show
  1. package/README.md +10 -8
  2. package/lib/index.js +140 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -24,8 +24,7 @@ https://github.com/user-attachments/assets/806cac11-3348-48b7-95a0-0c98fd61c873
24
24
  - **Tab Management** - Multiple tabs with native OS dialog picker (Cmd+click or Tab button)
25
25
  - **Clipboard Integration** - Ctrl+C/X/V for copy/cut/paste (uses system clipboard)
26
26
  - **URL Navigation** - Press Ctrl+L to focus address bar
27
- - **Mobile Testing** - Use `--mobile` flag for mobile viewport
28
- - **Zoom Control** - Adjust page scale with `--scale` option
27
+ - **Hint Mode** - Vimium-style keyboard navigation (Ctrl+H)
29
28
 
30
29
  ## Requirements
31
30
 
@@ -67,11 +66,14 @@ zig build
67
66
  # Open a URL
68
67
  termweb open https://example.com
69
68
 
70
- # Mobile viewport
71
- termweb open https://example.com --mobile
69
+ # Clone Chrome profile (use existing logins, extensions, settings)
70
+ termweb open https://example.com --profile Default
72
71
 
73
- # Custom zoom
74
- termweb open https://example.com --scale 0.8
72
+ # App mode (hide navigation bar)
73
+ termweb open https://example.com --no-toolbar
74
+
75
+ # SSH-optimized (lower frame rate)
76
+ termweb open https://example.com --fps 12
75
77
 
76
78
  # Show help
77
79
  termweb help
@@ -89,9 +91,7 @@ termweb.open('https://example.com');
89
91
 
90
92
  // With options
91
93
  termweb.open('https://vscode.dev', {
92
- mobile: false, // Mobile viewport
93
94
  toolbar: false, // Hide navigation toolbar
94
- scale: 0.8, // Page zoom
95
95
  });
96
96
 
97
97
  // Check availability
@@ -144,6 +144,8 @@ Extensions can provide:
144
144
  | `Ctrl+[` | Go back |
145
145
  | `Ctrl+]` | Go forward |
146
146
  | `Ctrl+.` | Stop loading |
147
+ | `Ctrl+N` | New tab (about:blank) |
148
+ | `Ctrl+W` | Close tab (quit if last tab) |
147
149
  | `Ctrl+T` | Show tab picker |
148
150
  | `Ctrl+C` | Copy selection |
149
151
  | `Ctrl+X` | Cut selection |
package/lib/index.js CHANGED
@@ -36,7 +36,7 @@ for (const modulePath of searchPaths) {
36
36
  }
37
37
 
38
38
  /**
39
- * Open a URL in termweb
39
+ * Open a URL in termweb (blocking)
40
40
  * @param {string} url - URL to open
41
41
  * @param {Object} [options] - Options
42
42
  * @param {boolean} [options.toolbar=true] - Show navigation toolbar
@@ -62,6 +62,135 @@ function open(url, options = {}) {
62
62
  });
63
63
  }
64
64
 
65
+ /**
66
+ * Open a URL in termweb (non-blocking)
67
+ * Returns immediately, viewer runs in background
68
+ * @param {string} url - URL to open
69
+ * @param {Object} [options] - Same options as open()
70
+ * @returns {void}
71
+ */
72
+ function openAsync(url, options = {}) {
73
+ if (!native) {
74
+ throw new Error('Native module not found. Build with: zig build');
75
+ }
76
+ native.openAsync(url, options);
77
+ }
78
+
79
+ /**
80
+ * Evaluate JavaScript in the active viewer
81
+ * @param {string} script - JavaScript code to execute
82
+ * @returns {boolean} - true if successful
83
+ */
84
+ function evalJS(script) {
85
+ if (!native) {
86
+ return false;
87
+ }
88
+ return native.evalJS(script);
89
+ }
90
+
91
+ /**
92
+ * Close the active viewer
93
+ * @returns {boolean} - true if there was a viewer to close
94
+ */
95
+ function close() {
96
+ if (!native) {
97
+ return false;
98
+ }
99
+ return native.close();
100
+ }
101
+
102
+ /**
103
+ * Check if a viewer is currently open
104
+ * @returns {boolean}
105
+ */
106
+ function isOpen() {
107
+ if (!native) {
108
+ return false;
109
+ }
110
+ return native.isOpen();
111
+ }
112
+
113
+ /**
114
+ * Register a callback to be called when the viewer closes
115
+ * @param {Function} callback - Function to call on close
116
+ */
117
+ function onClose(callback) {
118
+ if (!native) {
119
+ return;
120
+ }
121
+ native.onClose(callback);
122
+ }
123
+
124
+ /**
125
+ * Register a callback to receive IPC messages from the browser
126
+ * Browser sends messages via: console.log('__TERMWEB_IPC__:' + yourMessage)
127
+ * @param {Function} callback - Function to call with the message string
128
+ */
129
+ function onMessage(callback) {
130
+ if (!native) {
131
+ return;
132
+ }
133
+ native.onMessage(callback);
134
+ }
135
+
136
+ /**
137
+ * Register a callback to receive key binding events
138
+ * Called when a key defined in keyBindings option is pressed
139
+ * @param {Function} callback - Function to call with (key, action)
140
+ */
141
+ function onKeyBinding(callback) {
142
+ if (!native) {
143
+ return;
144
+ }
145
+ native.onKeyBinding(callback);
146
+ }
147
+
148
+ /**
149
+ * Add a key binding dynamically
150
+ * @param {string} key - Single letter a-z
151
+ * @param {string} action - Action string to send when key is pressed
152
+ * @returns {boolean} - true if successful
153
+ */
154
+ function addKeyBinding(key, action) {
155
+ if (!native) {
156
+ return false;
157
+ }
158
+ return native.addKeyBinding(key, action);
159
+ }
160
+
161
+ /**
162
+ * Remove a key binding dynamically
163
+ * @param {string} key - Single letter a-z
164
+ * @returns {boolean} - true if successful
165
+ */
166
+ function removeKeyBinding(key) {
167
+ if (!native) {
168
+ return false;
169
+ }
170
+ return native.removeKeyBinding(key);
171
+ }
172
+
173
+ /**
174
+ * Send a message to the page via SDK IPC
175
+ * Page receives via: window.__termweb.onMessage(callback)
176
+ * @param {Object|string} message - Message to send (will be JSON serialized)
177
+ * @returns {boolean} - true if successful
178
+ */
179
+ function sendToPage(message) {
180
+ if (!native) {
181
+ return false;
182
+ }
183
+ const json = typeof message === 'string' ? message : JSON.stringify(message);
184
+ // Escape for JavaScript string literal
185
+ const escaped = json.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\n/g, '\\n').replace(/\r/g, '\\r');
186
+ const script = `(function(){
187
+ if(window.__termweb && window.__termweb._receive){
188
+ window.__termweb._receive('${escaped}');
189
+ }
190
+ })()`;
191
+ return native.evalJS(script);
192
+ }
193
+
65
194
  /**
66
195
  * Get termweb version
67
196
  * @returns {string}
@@ -94,6 +223,16 @@ function isAvailable() {
94
223
 
95
224
  module.exports = {
96
225
  open,
226
+ openAsync,
227
+ evalJS,
228
+ sendToPage,
229
+ close,
230
+ isOpen,
231
+ onClose,
232
+ onMessage,
233
+ onKeyBinding,
234
+ addKeyBinding,
235
+ removeKeyBinding,
97
236
  version,
98
237
  isSupported,
99
238
  isAvailable,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "termweb",
3
- "version": "0.9.2",
3
+ "version": "0.9.5",
4
4
  "description": "Web browser in your terminal using Kitty graphics protocol. SDK for building terminal apps with web technologies.",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {