@nativewindow/webview 1.0.4 → 1.0.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.
- package/dist/index.d.ts +125 -3
- package/dist/index.js +42 -2
- package/package.json +8 -10
- package/native-window.d.ts +0 -264
- package/native-window.js +0 -62
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,129 @@
|
|
|
1
|
-
|
|
1
|
+
declare const checkRuntime: () => RuntimeInfo, ensureRuntime: () => RuntimeInfo, loadHtmlOrigin: () => string;
|
|
2
2
|
export { checkRuntime, ensureRuntime, loadHtmlOrigin };
|
|
3
|
-
|
|
3
|
+
/** Information about the native webview runtime. */
|
|
4
|
+
export interface RuntimeInfo {
|
|
5
|
+
/** Whether the webview runtime is available. */
|
|
6
|
+
available: boolean;
|
|
7
|
+
/** The version string of the runtime, if detected. */
|
|
8
|
+
version?: string;
|
|
9
|
+
/** The current platform: "macos", "windows", "linux", or "unsupported". */
|
|
10
|
+
platform: "macos" | "windows" | "linux" | "unsupported";
|
|
11
|
+
}
|
|
12
|
+
export interface WindowOptions {
|
|
13
|
+
/** Window title. Default: "" */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** Inner width in logical pixels. Default: 800 */
|
|
16
|
+
width?: number;
|
|
17
|
+
/** Inner height in logical pixels. Default: 600 */
|
|
18
|
+
height?: number;
|
|
19
|
+
/** X position in screen coordinates */
|
|
20
|
+
x?: number;
|
|
21
|
+
/** Y position in screen coordinates */
|
|
22
|
+
y?: number;
|
|
23
|
+
/** Minimum inner width */
|
|
24
|
+
minWidth?: number;
|
|
25
|
+
/** Minimum inner height */
|
|
26
|
+
minHeight?: number;
|
|
27
|
+
/** Maximum inner width */
|
|
28
|
+
maxWidth?: number;
|
|
29
|
+
/** Maximum inner height */
|
|
30
|
+
maxHeight?: number;
|
|
31
|
+
/** Allow resizing. Default: true */
|
|
32
|
+
resizable?: boolean;
|
|
33
|
+
/** Show window decorations (title bar, borders). Default: true */
|
|
34
|
+
decorations?: boolean;
|
|
35
|
+
/** Transparent window background. Default: false */
|
|
36
|
+
transparent?: boolean;
|
|
37
|
+
/** Always on top of other windows. Default: false */
|
|
38
|
+
alwaysOnTop?: boolean;
|
|
39
|
+
/** Initially visible. Default: true */
|
|
40
|
+
visible?: boolean;
|
|
41
|
+
/** Enable devtools. Default: false */
|
|
42
|
+
devtools?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Content Security Policy to inject at document start.
|
|
45
|
+
* When set, a `<meta http-equiv="Content-Security-Policy">` tag is injected
|
|
46
|
+
* before any page scripts run.
|
|
47
|
+
*
|
|
48
|
+
* **Limitation:** The CSP is applied via a `<meta>` tag at `DOMContentLoaded`,
|
|
49
|
+
* so scripts executing before that event are not restricted. Meta-tag CSP also
|
|
50
|
+
* cannot enforce `frame-ancestors` or `report-uri` directives. For stronger
|
|
51
|
+
* enforcement, serve pages via the custom protocol handler with a real HTTP
|
|
52
|
+
* `Content-Security-Policy` header.
|
|
53
|
+
*
|
|
54
|
+
* @example `"default-src 'self'; script-src 'self' 'unsafe-inline'"`
|
|
55
|
+
*/
|
|
56
|
+
csp?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Trusted origins for IPC messages at the native layer.
|
|
59
|
+
* When set, only messages whose source URL origin matches one of these
|
|
60
|
+
* entries are forwarded to the host. Messages from other origins are
|
|
61
|
+
* silently dropped.
|
|
62
|
+
*
|
|
63
|
+
* Each entry should be a full origin string (scheme + host + optional port),
|
|
64
|
+
* e.g. `"https://example.com"`. No trailing slash.
|
|
65
|
+
*
|
|
66
|
+
* @security Defense-in-depth. For application-level origin filtering,
|
|
67
|
+
* use `trustedOrigins` in `createChannel()` from `native-window-ipc`.
|
|
68
|
+
*
|
|
69
|
+
* @example `["https://myapp.com", "https://cdn.myapp.com"]`
|
|
70
|
+
*/
|
|
71
|
+
trustedOrigins?: string[];
|
|
72
|
+
/**
|
|
73
|
+
* Allowed hosts for navigation restriction.
|
|
74
|
+
* When set and non-empty, ALL navigations (including `loadUrl()`, link
|
|
75
|
+
* clicks, form submissions, and redirects) are restricted to URLs whose
|
|
76
|
+
* host matches one of these patterns.
|
|
77
|
+
*
|
|
78
|
+
* Supports wildcard prefixes: `"*.example.com"` matches any subdomain
|
|
79
|
+
* of `example.com` and `example.com` itself.
|
|
80
|
+
*
|
|
81
|
+
* Internal navigations (`about:blank`, `loadHtml()` content) are always
|
|
82
|
+
* permitted. When unset or empty, all hosts are allowed.
|
|
83
|
+
*
|
|
84
|
+
* @example `["myapp.com", "*.cdn.myapp.com"]`
|
|
85
|
+
*/
|
|
86
|
+
allowedHosts?: string[];
|
|
87
|
+
/**
|
|
88
|
+
* Allow the webview to access the camera when requested.
|
|
89
|
+
* Default: false (all camera requests are denied).
|
|
90
|
+
* @note Not yet enforced in the wry backend. The OS default (prompt user) applies.
|
|
91
|
+
*/
|
|
92
|
+
allowCamera?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Allow the webview to access the microphone when requested.
|
|
95
|
+
* Default: false (all microphone requests are denied).
|
|
96
|
+
* @note Not yet enforced in the wry backend. The OS default (prompt user) applies.
|
|
97
|
+
*/
|
|
98
|
+
allowMicrophone?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Allow the webview to use the File System Access API
|
|
101
|
+
* (`showOpenFilePicker`, `showSaveFilePicker`, `showDirectoryPicker`).
|
|
102
|
+
* Default: false (all file system access requests are denied).
|
|
103
|
+
* @note Not yet enforced in the wry backend. The OS default applies.
|
|
104
|
+
*/
|
|
105
|
+
allowFileSystem?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Path to a PNG or ICO file for the window icon (title bar).
|
|
108
|
+
* On macOS this option is silently ignored (macOS doesn't support
|
|
109
|
+
* per-window icons). Relative paths resolve from the working directory.
|
|
110
|
+
*/
|
|
111
|
+
icon?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Run the webview in incognito (private) mode.
|
|
114
|
+
* When `true`, no cookies, cache, or other browsing data are persisted to disk.
|
|
115
|
+
* Each window starts with a clean, isolated session and all data is discarded
|
|
116
|
+
* when the window closes.
|
|
117
|
+
*
|
|
118
|
+
* Platform notes:
|
|
119
|
+
* - **macOS**: Uses `WKWebsiteDataStore.nonPersistentDataStore()` (WKWebView).
|
|
120
|
+
* - **Windows**: Enables `IsInPrivateModeEnabled` on the WebView2 controller.
|
|
121
|
+
* - **Linux**: Uses a temporary in-memory WebContext (no persistent storage).
|
|
122
|
+
*
|
|
123
|
+
* Default: `false`
|
|
124
|
+
*/
|
|
125
|
+
incognito?: boolean;
|
|
126
|
+
}
|
|
4
127
|
/**
|
|
5
128
|
* Operations that execute arbitrary code in the webview context.
|
|
6
129
|
* Grouped under {@link NativeWindow.unsafe} to signal injection risk.
|
|
@@ -75,7 +198,6 @@ export interface CookieInfo {
|
|
|
75
198
|
/** Expiry as Unix timestamp (seconds). -1 for session cookies. */
|
|
76
199
|
expires: number;
|
|
77
200
|
}
|
|
78
|
-
type WindowOptions = import('../native-window.js').WindowOptions;
|
|
79
201
|
/**
|
|
80
202
|
* A native OS window with an embedded webview.
|
|
81
203
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
2
|
//#region index.ts
|
|
3
|
+
var _require = createRequire(import.meta.url);
|
|
4
|
+
var _platforms = {
|
|
5
|
+
"darwin-arm64": {
|
|
6
|
+
pkg: "@nativewindow/webview-darwin-arm64",
|
|
7
|
+
file: "native-window.darwin-arm64.node"
|
|
8
|
+
},
|
|
9
|
+
"darwin-x64": {
|
|
10
|
+
pkg: "@nativewindow/webview-darwin-x64",
|
|
11
|
+
file: "native-window.darwin-x64.node"
|
|
12
|
+
},
|
|
13
|
+
"win32-x64": {
|
|
14
|
+
pkg: "@nativewindow/webview-win32-x64-msvc",
|
|
15
|
+
file: "native-window.win32-x64-msvc.node"
|
|
16
|
+
},
|
|
17
|
+
"win32-arm64": {
|
|
18
|
+
pkg: "@nativewindow/webview-win32-arm64-msvc",
|
|
19
|
+
file: "native-window.win32-arm64-msvc.node"
|
|
20
|
+
},
|
|
21
|
+
"linux-x64": {
|
|
22
|
+
pkg: "@nativewindow/webview-linux-x64-gnu",
|
|
23
|
+
file: "native-window.linux-x64-gnu.node"
|
|
24
|
+
},
|
|
25
|
+
"linux-arm64": {
|
|
26
|
+
pkg: "@nativewindow/webview-linux-arm64-gnu",
|
|
27
|
+
file: "native-window.linux-arm64-gnu.node"
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var _platformKey = `${process.platform}-${process.arch}`;
|
|
31
|
+
var _entry = _platforms[_platformKey];
|
|
32
|
+
if (!_entry) throw new Error(`Unsupported platform: ${_platformKey}`);
|
|
33
|
+
function _tryRequire(id) {
|
|
34
|
+
try {
|
|
35
|
+
return _require(id);
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var _nativeBinding = _tryRequire(`./${_entry.file}`) ?? _tryRequire(`../${_entry.file}`) ?? _tryRequire(_entry.pkg);
|
|
41
|
+
if (!_nativeBinding) throw new Error(`Failed to load native binding for platform: ${_platformKey}. Ensure the correct platform package is installed or the .node file exists.`);
|
|
42
|
+
var { NativeWindow: _NativeWindow, init, pumpEvents, checkRuntime, ensureRuntime, loadHtmlOrigin } = _nativeBinding;
|
|
3
43
|
var _pump = null;
|
|
4
44
|
var _windowCount = 0;
|
|
5
45
|
function ensureInit() {
|
|
@@ -37,7 +77,7 @@ var NativeWindow = class {
|
|
|
37
77
|
constructor(options) {
|
|
38
78
|
ensureInit();
|
|
39
79
|
_windowCount++;
|
|
40
|
-
this._native = new
|
|
80
|
+
this._native = new _NativeWindow(options);
|
|
41
81
|
this._native.onClose(() => this._handleClose());
|
|
42
82
|
}
|
|
43
83
|
/** @internal */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nativewindow/webview",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Native OS webview windows for Bun & Node.js (beta)",
|
|
5
5
|
"homepage": "https://nativewindow.fcannizzaro.com",
|
|
6
6
|
"bugs": {
|
|
@@ -23,8 +23,6 @@
|
|
|
23
23
|
],
|
|
24
24
|
"files": [
|
|
25
25
|
"dist",
|
|
26
|
-
"native-window.js",
|
|
27
|
-
"native-window.d.ts",
|
|
28
26
|
"README.md",
|
|
29
27
|
"LICENSE"
|
|
30
28
|
],
|
|
@@ -54,7 +52,7 @@
|
|
|
54
52
|
},
|
|
55
53
|
"devDependencies": {
|
|
56
54
|
"@napi-rs/cli": "^3.6.0",
|
|
57
|
-
"@types/
|
|
55
|
+
"@types/node": "^25.5.2",
|
|
58
56
|
"vite": "^8.0.3",
|
|
59
57
|
"vite-plugin-dts": "^4.5.4"
|
|
60
58
|
},
|
|
@@ -62,12 +60,12 @@
|
|
|
62
60
|
"typescript": "^6.0.2"
|
|
63
61
|
},
|
|
64
62
|
"optionalDependencies": {
|
|
65
|
-
"@nativewindow/webview-darwin-arm64": "1.0.
|
|
66
|
-
"@nativewindow/webview-darwin-x64": "1.0.
|
|
67
|
-
"@nativewindow/webview-linux-arm64-gnu": "1.0.
|
|
68
|
-
"@nativewindow/webview-linux-x64-gnu": "1.0.
|
|
69
|
-
"@nativewindow/webview-win32-arm64-msvc": "1.0.
|
|
70
|
-
"@nativewindow/webview-win32-x64-msvc": "1.0.
|
|
63
|
+
"@nativewindow/webview-darwin-arm64": "1.0.5",
|
|
64
|
+
"@nativewindow/webview-darwin-x64": "1.0.5",
|
|
65
|
+
"@nativewindow/webview-linux-arm64-gnu": "1.0.5",
|
|
66
|
+
"@nativewindow/webview-linux-x64-gnu": "1.0.5",
|
|
67
|
+
"@nativewindow/webview-win32-arm64-msvc": "1.0.5",
|
|
68
|
+
"@nativewindow/webview-win32-x64-msvc": "1.0.5"
|
|
71
69
|
},
|
|
72
70
|
"napi": {
|
|
73
71
|
"binaryName": "native-window",
|
package/native-window.d.ts
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
// Auto-generated type declarations for the native addon.
|
|
3
|
-
// These will be overwritten by `napi build` but serve as
|
|
4
|
-
// a reference during development.
|
|
5
|
-
|
|
6
|
-
export interface WindowOptions {
|
|
7
|
-
/** Window title. Default: "" */
|
|
8
|
-
title?: string;
|
|
9
|
-
/** Inner width in logical pixels. Default: 800 */
|
|
10
|
-
width?: number;
|
|
11
|
-
/** Inner height in logical pixels. Default: 600 */
|
|
12
|
-
height?: number;
|
|
13
|
-
/** X position in screen coordinates */
|
|
14
|
-
x?: number;
|
|
15
|
-
/** Y position in screen coordinates */
|
|
16
|
-
y?: number;
|
|
17
|
-
/** Minimum inner width */
|
|
18
|
-
minWidth?: number;
|
|
19
|
-
/** Minimum inner height */
|
|
20
|
-
minHeight?: number;
|
|
21
|
-
/** Maximum inner width */
|
|
22
|
-
maxWidth?: number;
|
|
23
|
-
/** Maximum inner height */
|
|
24
|
-
maxHeight?: number;
|
|
25
|
-
/** Allow resizing. Default: true */
|
|
26
|
-
resizable?: boolean;
|
|
27
|
-
/** Show window decorations (title bar, borders). Default: true */
|
|
28
|
-
decorations?: boolean;
|
|
29
|
-
/** Transparent window background. Default: false */
|
|
30
|
-
transparent?: boolean;
|
|
31
|
-
/** Always on top of other windows. Default: false */
|
|
32
|
-
alwaysOnTop?: boolean;
|
|
33
|
-
/** Initially visible. Default: true */
|
|
34
|
-
visible?: boolean;
|
|
35
|
-
/** Enable devtools. Default: false */
|
|
36
|
-
devtools?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Content Security Policy to inject at document start.
|
|
39
|
-
* When set, a `<meta http-equiv="Content-Security-Policy">` tag is injected
|
|
40
|
-
* before any page scripts run.
|
|
41
|
-
*
|
|
42
|
-
* **Limitation:** The CSP is applied via a `<meta>` tag at `DOMContentLoaded`,
|
|
43
|
-
* so scripts executing before that event are not restricted. Meta-tag CSP also
|
|
44
|
-
* cannot enforce `frame-ancestors` or `report-uri` directives. For stronger
|
|
45
|
-
* enforcement, serve pages via the custom protocol handler with a real HTTP
|
|
46
|
-
* `Content-Security-Policy` header.
|
|
47
|
-
*
|
|
48
|
-
* @example `"default-src 'self'; script-src 'self' 'unsafe-inline'"`
|
|
49
|
-
*/
|
|
50
|
-
csp?: string;
|
|
51
|
-
/**
|
|
52
|
-
* Trusted origins for IPC messages at the native layer.
|
|
53
|
-
* When set, only messages whose source URL origin matches one of these
|
|
54
|
-
* entries are forwarded to the host. Messages from other origins are
|
|
55
|
-
* silently dropped.
|
|
56
|
-
*
|
|
57
|
-
* Each entry should be a full origin string (scheme + host + optional port),
|
|
58
|
-
* e.g. `"https://example.com"`. No trailing slash.
|
|
59
|
-
*
|
|
60
|
-
* @security Defense-in-depth. For application-level origin filtering,
|
|
61
|
-
* use `trustedOrigins` in `createChannel()` from `native-window-ipc`.
|
|
62
|
-
*
|
|
63
|
-
* @example `["https://myapp.com", "https://cdn.myapp.com"]`
|
|
64
|
-
*/
|
|
65
|
-
trustedOrigins?: string[];
|
|
66
|
-
/**
|
|
67
|
-
* Allowed hosts for navigation restriction.
|
|
68
|
-
* When set and non-empty, ALL navigations (including `loadUrl()`, link
|
|
69
|
-
* clicks, form submissions, and redirects) are restricted to URLs whose
|
|
70
|
-
* host matches one of these patterns.
|
|
71
|
-
*
|
|
72
|
-
* Supports wildcard prefixes: `"*.example.com"` matches any subdomain
|
|
73
|
-
* of `example.com` and `example.com` itself.
|
|
74
|
-
*
|
|
75
|
-
* Internal navigations (`about:blank`, `loadHtml()` content) are always
|
|
76
|
-
* permitted. When unset or empty, all hosts are allowed.
|
|
77
|
-
*
|
|
78
|
-
* @example `["myapp.com", "*.cdn.myapp.com"]`
|
|
79
|
-
*/
|
|
80
|
-
allowedHosts?: string[];
|
|
81
|
-
/**
|
|
82
|
-
* Allow the webview to access the camera when requested.
|
|
83
|
-
* Default: false (all camera requests are denied).
|
|
84
|
-
* @note Not yet enforced in the wry backend. The OS default (prompt user) applies.
|
|
85
|
-
*/
|
|
86
|
-
allowCamera?: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Allow the webview to access the microphone when requested.
|
|
89
|
-
* Default: false (all microphone requests are denied).
|
|
90
|
-
* @note Not yet enforced in the wry backend. The OS default (prompt user) applies.
|
|
91
|
-
*/
|
|
92
|
-
allowMicrophone?: boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Allow the webview to use the File System Access API
|
|
95
|
-
* (`showOpenFilePicker`, `showSaveFilePicker`, `showDirectoryPicker`).
|
|
96
|
-
* Default: false (all file system access requests are denied).
|
|
97
|
-
* @note Not yet enforced in the wry backend. The OS default applies.
|
|
98
|
-
*/
|
|
99
|
-
allowFileSystem?: boolean;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Path to a PNG or ICO file for the window icon (title bar).
|
|
103
|
-
* On macOS this option is silently ignored (macOS doesn't support
|
|
104
|
-
* per-window icons). Relative paths resolve from the working directory.
|
|
105
|
-
*/
|
|
106
|
-
icon?: string;
|
|
107
|
-
/**
|
|
108
|
-
* Run the webview in incognito (private) mode.
|
|
109
|
-
* When `true`, no cookies, cache, or other browsing data are persisted to disk.
|
|
110
|
-
* Each window starts with a clean, isolated session and all data is discarded
|
|
111
|
-
* when the window closes.
|
|
112
|
-
*
|
|
113
|
-
* Platform notes:
|
|
114
|
-
* - **macOS**: Uses `WKWebsiteDataStore.nonPersistentDataStore()` (WKWebView).
|
|
115
|
-
* - **Windows**: Enables `IsInPrivateModeEnabled` on the WebView2 controller.
|
|
116
|
-
* - **Linux**: Uses a temporary in-memory WebContext (no persistent storage).
|
|
117
|
-
*
|
|
118
|
-
* Default: `false`
|
|
119
|
-
*/
|
|
120
|
-
incognito?: boolean;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export class NativeWindow {
|
|
124
|
-
constructor(options?: WindowOptions);
|
|
125
|
-
|
|
126
|
-
/** Unique window ID */
|
|
127
|
-
readonly id: number;
|
|
128
|
-
|
|
129
|
-
// Content loading
|
|
130
|
-
loadUrl(url: string): void;
|
|
131
|
-
loadHtml(html: string): void;
|
|
132
|
-
evaluateJs(script: string): void;
|
|
133
|
-
postMessage(message: string): void;
|
|
134
|
-
|
|
135
|
-
// Window control
|
|
136
|
-
setTitle(title: string): void;
|
|
137
|
-
setSize(width: number, height: number): void;
|
|
138
|
-
setMinSize(width: number, height: number): void;
|
|
139
|
-
setMaxSize(width: number, height: number): void;
|
|
140
|
-
setPosition(x: number, y: number): void;
|
|
141
|
-
setResizable(resizable: boolean): void;
|
|
142
|
-
setDecorations(decorations: boolean): void;
|
|
143
|
-
setAlwaysOnTop(alwaysOnTop: boolean): void;
|
|
144
|
-
/** Set the window icon from a PNG or ICO file path. Ignored on macOS. */
|
|
145
|
-
setIcon(path: string): void;
|
|
146
|
-
|
|
147
|
-
// Window state
|
|
148
|
-
show(): void;
|
|
149
|
-
hide(): void;
|
|
150
|
-
close(): void;
|
|
151
|
-
focus(): void;
|
|
152
|
-
maximize(): void;
|
|
153
|
-
minimize(): void;
|
|
154
|
-
unmaximize(): void;
|
|
155
|
-
reload(): void;
|
|
156
|
-
|
|
157
|
-
// Event handlers
|
|
158
|
-
onMessage(callback: (message: string, sourceUrl: string) => void): void;
|
|
159
|
-
onClose(callback: () => void): void;
|
|
160
|
-
onResize(callback: (width: number, height: number) => void): void;
|
|
161
|
-
onMove(callback: (x: number, y: number) => void): void;
|
|
162
|
-
onFocus(callback: () => void): void;
|
|
163
|
-
onBlur(callback: () => void): void;
|
|
164
|
-
onPageLoad(callback: (event: "started" | "finished", url: string) => void): void;
|
|
165
|
-
onTitleChanged(callback: (title: string) => void): void;
|
|
166
|
-
onReload(callback: () => void): void;
|
|
167
|
-
onNavigationBlocked(callback: (url: string) => void): void;
|
|
168
|
-
|
|
169
|
-
// Cookie access
|
|
170
|
-
getCookies(url?: string): void;
|
|
171
|
-
onCookies(callback: (cookies: string) => void): void;
|
|
172
|
-
clearCookies(host?: string): void;
|
|
173
|
-
|
|
174
|
-
// Devtools
|
|
175
|
-
/** Open the browser devtools panel. Requires `devtools: true` in options. */
|
|
176
|
-
openDevtools(): void;
|
|
177
|
-
/** Close the browser devtools panel. */
|
|
178
|
-
closeDevtools(): void;
|
|
179
|
-
/** Check whether the devtools panel is currently open. */
|
|
180
|
-
isDevtoolsOpen(): boolean;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/** Initialize the native window system. Must be called once before creating any windows. */
|
|
184
|
-
export function init(): void;
|
|
185
|
-
|
|
186
|
-
/** Process pending native UI events. Call periodically (~16ms) to keep windows responsive. */
|
|
187
|
-
export function pumpEvents(): void;
|
|
188
|
-
|
|
189
|
-
/** Information about the native webview runtime. */
|
|
190
|
-
export interface RuntimeInfo {
|
|
191
|
-
/** Whether the webview runtime is available. */
|
|
192
|
-
available: boolean;
|
|
193
|
-
/** The version string of the runtime, if detected. */
|
|
194
|
-
version?: string;
|
|
195
|
-
/** The current platform: "macos", "windows", "linux", or "unsupported". */
|
|
196
|
-
platform: "macos" | "windows" | "linux" | "unsupported";
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Check if the native webview runtime is available.
|
|
201
|
-
*
|
|
202
|
-
* - **macOS**: Always returns available (WKWebView is a system framework).
|
|
203
|
-
* - **Windows**: Detects WebView2 via `GetAvailableCoreWebView2BrowserVersionString`.
|
|
204
|
-
* - **Linux**: Always returns available (WebKitGTK is required at build time).
|
|
205
|
-
* - **Other**: Returns `{ available: false, platform: "unsupported" }`.
|
|
206
|
-
*/
|
|
207
|
-
export function checkRuntime(): RuntimeInfo;
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Ensure the native webview runtime is available, installing it if necessary.
|
|
211
|
-
*
|
|
212
|
-
* - **macOS**: Returns immediately (WKWebView is always available).
|
|
213
|
-
* - **Windows**: If WebView2 is missing, downloads the Evergreen Bootstrapper
|
|
214
|
-
* (~2MB) from Microsoft and runs it silently. Throws on failure.
|
|
215
|
-
* - **Linux**: Returns immediately (WebKitGTK is required at build time).
|
|
216
|
-
* - **Other**: Throws an error.
|
|
217
|
-
*
|
|
218
|
-
* @security This function downloads and executes a Microsoft-signed binary
|
|
219
|
-
* from the internet (Windows only). Authenticode signature verification is
|
|
220
|
-
* performed before execution; unverified binaries are never run.
|
|
221
|
-
*
|
|
222
|
-
* **Do not call in an elevated (Administrator) context without explicit user
|
|
223
|
-
* consent.** The silent installer applies system-wide. Prefer calling
|
|
224
|
-
* {@link checkRuntime} first to avoid unnecessary network requests when the
|
|
225
|
-
* runtime is already present.
|
|
226
|
-
*/
|
|
227
|
-
export function ensureRuntime(): RuntimeInfo;
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Escape a string for safe embedding inside a JavaScript string literal.
|
|
231
|
-
* Handles backslashes, quotes, newlines, null bytes, closing `</script>` tags,
|
|
232
|
-
* and Unicode line/paragraph separators (U+2028, U+2029).
|
|
233
|
-
*
|
|
234
|
-
* @security Use this when interpolating untrusted input into `win.unsafe.evaluateJs()` calls.
|
|
235
|
-
*
|
|
236
|
-
* @example
|
|
237
|
-
* ```ts
|
|
238
|
-
* import { sanitizeForJs } from "native-window";
|
|
239
|
-
*
|
|
240
|
-
* const userInput = 'He said "hello"\n<script>alert(1)</script>';
|
|
241
|
-
* win.unsafe.evaluateJs(`display("${sanitizeForJs(userInput)}")`);
|
|
242
|
-
* ```
|
|
243
|
-
*/
|
|
244
|
-
export function sanitizeForJs(input: string): string;
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Returns the origin of pages loaded via `loadHtml()`.
|
|
248
|
-
*
|
|
249
|
-
* Use this in `trustedOrigins` to restrict IPC messages to only accept
|
|
250
|
-
* messages from `loadHtml()` content.
|
|
251
|
-
*
|
|
252
|
-
* - macOS/Linux: `"nativewindow://localhost"`
|
|
253
|
-
* - Windows: `"https://nativewindow.localhost"`
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* ```ts
|
|
257
|
-
* import { NativeWindow, loadHtmlOrigin } from "@nativewindow/webview";
|
|
258
|
-
*
|
|
259
|
-
* const win = new NativeWindow({
|
|
260
|
-
* trustedOrigins: [loadHtmlOrigin()],
|
|
261
|
-
* });
|
|
262
|
-
* ```
|
|
263
|
-
*/
|
|
264
|
-
export function loadHtmlOrigin(): string;
|
package/native-window.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
// JS loader for the native addon.
|
|
3
|
-
// Tries local .node files first (development), then per-platform npm packages (production).
|
|
4
|
-
|
|
5
|
-
import { createRequire } from "node:module";
|
|
6
|
-
|
|
7
|
-
const require = createRequire(import.meta.url);
|
|
8
|
-
const { platform, arch } = process;
|
|
9
|
-
|
|
10
|
-
const platforms = {
|
|
11
|
-
"darwin-arm64": {
|
|
12
|
-
pkg: "@nativewindow/webview-darwin-arm64",
|
|
13
|
-
file: "native-window.darwin-arm64.node",
|
|
14
|
-
},
|
|
15
|
-
"darwin-x64": {
|
|
16
|
-
pkg: "@nativewindow/webview-darwin-x64",
|
|
17
|
-
file: "native-window.darwin-x64.node",
|
|
18
|
-
},
|
|
19
|
-
"win32-x64": {
|
|
20
|
-
pkg: "@nativewindow/webview-win32-x64-msvc",
|
|
21
|
-
file: "native-window.win32-x64-msvc.node",
|
|
22
|
-
},
|
|
23
|
-
"win32-arm64": {
|
|
24
|
-
pkg: "@nativewindow/webview-win32-arm64-msvc",
|
|
25
|
-
file: "native-window.win32-arm64-msvc.node",
|
|
26
|
-
},
|
|
27
|
-
"linux-x64": {
|
|
28
|
-
pkg: "@nativewindow/webview-linux-x64-gnu",
|
|
29
|
-
file: "native-window.linux-x64-gnu.node",
|
|
30
|
-
},
|
|
31
|
-
"linux-arm64": {
|
|
32
|
-
pkg: "@nativewindow/webview-linux-arm64-gnu",
|
|
33
|
-
file: "native-window.linux-arm64-gnu.node",
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const key = `${platform}-${arch}`;
|
|
38
|
-
const entry = platforms[key];
|
|
39
|
-
|
|
40
|
-
if (!entry) {
|
|
41
|
-
throw new Error(`Unsupported platform: ${key}`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const tryRequire = (id) => {
|
|
45
|
-
try {
|
|
46
|
-
return require(id);
|
|
47
|
-
} catch {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const nativeBinding = tryRequire(`./${entry.file}`) ?? tryRequire(entry.pkg);
|
|
53
|
-
|
|
54
|
-
if (!nativeBinding) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
`Failed to load native binding for platform: ${key}. ` +
|
|
57
|
-
`Ensure the correct platform package is installed or the .node file exists.`,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const { NativeWindow, init, pumpEvents, checkRuntime, ensureRuntime, loadHtmlOrigin } =
|
|
62
|
-
nativeBinding;
|