electrobun 0.0.2 → 0.0.3
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/.colab.json +1 -0
- package/README.md +14 -12
- package/bun.lockb +0 -0
- package/dist/bsdiff +0 -0
- package/dist/bspatch +0 -0
- package/dist/webview +0 -0
- package/docs-old/architecture.md +46 -0
- package/documentation/README.md +41 -0
- package/documentation/babel.config.js +3 -0
- package/documentation/blog/2024-08-20-electrobun.md +22 -0
- package/documentation/blog/authors.yml +8 -0
- package/documentation/blog/tags.yml +0 -0
- package/documentation/docs/apis/Application Icons.md +9 -0
- package/documentation/docs/apis/Bundled Assets.md +95 -0
- package/documentation/docs/apis/browser/DraggableRegions.md +36 -0
- package/documentation/docs/apis/browser/Electrobun Webview Tag.md +200 -0
- package/documentation/docs/apis/browser/Electroview Class.md +158 -0
- package/documentation/docs/apis/browser/GlobalProperties.md +11 -0
- package/documentation/docs/apis/browser/index.md +25 -0
- package/documentation/docs/apis/bun/ApplicationMenu.md +141 -0
- package/documentation/docs/apis/bun/BrowserView.md +513 -0
- package/documentation/docs/apis/bun/BrowserWindow.md +423 -0
- package/documentation/docs/apis/bun/ContextMenu.md +50 -0
- package/documentation/docs/apis/bun/Events.md +50 -0
- package/documentation/docs/apis/bun/PATHS.md +17 -0
- package/documentation/docs/apis/bun/Tray.md +115 -0
- package/documentation/docs/apis/bun/Updater.md +74 -0
- package/documentation/docs/apis/bun/Utils.md +51 -0
- package/documentation/docs/apis/bun/index.md +26 -0
- package/documentation/docs/apis/cli/Electrobun.config.md +97 -0
- package/documentation/docs/apis/cli/cli args.md +76 -0
- package/documentation/docs/guides/Architecture/Events.md +19 -0
- package/documentation/docs/guides/Architecture/IPC and Isolation.md +20 -0
- package/documentation/docs/guides/Architecture/Overview.md +140 -0
- package/documentation/docs/guides/Architecture/Updates.md +7 -0
- package/documentation/docs/guides/Architecture/Webview Tag.md +5 -0
- package/documentation/docs/guides/Compatability.md +8 -0
- package/documentation/docs/guides/Getting Started/Creating UI.md +147 -0
- package/documentation/docs/guides/Getting Started/Distributing.md +116 -0
- package/documentation/docs/guides/Getting Started/Getting Started.md +7 -0
- package/documentation/docs/guides/Getting Started/Hello World.md +93 -0
- package/documentation/docs/guides/Getting Started/What is Electrobun.md +39 -0
- package/documentation/docs/guides/Guides/Build UI with React +0 -0
- package/documentation/docs/guides/Guides/Build UI with Solidjs +0 -0
- package/documentation/docs/guides/Guides/Build a Web Browser +0 -0
- package/documentation/docs/guides/Guides/Bun <-> Browser RPC +0 -0
- package/documentation/docs/guides/Guides/Using Tailwind +0 -0
- package/documentation/docusaurus.config.ts +153 -0
- package/documentation/package-lock.json +14530 -0
- package/documentation/package.json +47 -0
- package/documentation/sidebars.ts +32 -0
- package/documentation/src/components/HomepageFeatures/index.tsx +70 -0
- package/documentation/src/components/HomepageFeatures/styles.module.css +11 -0
- package/documentation/src/css/custom.css +30 -0
- package/documentation/src/pages/index.module.css +23 -0
- package/documentation/src/pages/index.tsx +137 -0
- package/documentation/static/.nojekyll +0 -0
- package/documentation/static/img/electrobun-logo-256.png +0 -0
- package/documentation/static/img/electrobun-logo-32.png +0 -0
- package/documentation/tsconfig.json +7 -0
- package/package.json +11 -6
- package/src/browser/index.ts +2 -2
- package/src/bun/core/BrowserView.ts +14 -1
- package/src/cli/build/electrobun +0 -0
- package/src/cli/index.ts +3 -1
- package/docs/architecture.md +0 -84
- /package/{docs → docs-old}/api/bun-api.md +0 -0
- /package/{docs → docs-old}/api/view-api.md +0 -0
- /package/{docs → docs-old}/electrobun-config.md +0 -0
- /package/{docs → docs-old}/getting-started.md +0 -0
- /package/{docs → docs-old}/node_modules/.cache/webpack/client-development-en/0.pack +0 -0
- /package/{docs → docs-old}/node_modules/.cache/webpack/client-development-en/index.pack +0 -0
package/.colab.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"v":1,"name":"electrobun","type":"project","url":"","icon":"","config":{}}
|
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
Electrobun aims to be a complete **solution-in-a-box** for building, updating, and shipping ultra fast, tiny, and cross-platform desktop applications written in Typescript.
|
|
14
14
|
Under the hood it uses <a href="https://bun.sh">bun</a> to execute the main process and to bundle webview typescript, and has native bindings written in <a href="https://ziglang.org/">zig</a>.
|
|
15
15
|
|
|
16
|
+
Visit <a href="https://www.electrobun.dev/">Electrobun.dev</a> to see api documentation, guides, and more.
|
|
17
|
+
|
|
16
18
|
**Project Goals**
|
|
17
19
|
|
|
18
20
|
- Write typescript for the main process and webviews without having to think about it.
|
|
@@ -23,7 +25,7 @@ Under the hood it uses <a href="https://bun.sh">bun</a> to execute the main proc
|
|
|
23
25
|
|
|
24
26
|
## Architecture
|
|
25
27
|
|
|
26
|
-
Read about how Electrobun is designed, and why, in our <a href="https://
|
|
28
|
+
Read about how Electrobun is designed, and why, in our <a href="https://www.electrobun.dev/docs/guides/Architecture/Overview">architecture docs</a>.
|
|
27
29
|
|
|
28
30
|
## Roadmap
|
|
29
31
|
|
|
@@ -31,17 +33,17 @@ See the detailed <a href="https://github.com/blackboardsh/electrobun/issues/2">d
|
|
|
31
33
|
|
|
32
34
|
**High level roadmap**
|
|
33
35
|
|
|
34
|
-
| | Milestones | Description
|
|
35
|
-
| :-- | :-------------------- |
|
|
36
|
-
| ✅ | Core Architecture | Ship a working proof of concept with most of the core architecture wired up
|
|
37
|
-
| ✅ | Packaging and signing | Packaging and code signing for MacOS
|
|
38
|
-
| ✅ | Shipping updates | Integrated auto-updator
|
|
39
|
-
| ✅ | Webview Tag | Cross browser electrobun implementation of the <webview> tag that electron has, for isolated nested webviews
|
|
40
|
-
| ✅ | Port
|
|
41
|
-
| | Custom Web Runtime | Optionally use a cross-platform web runtime (Chromium) instead of the system's native webview
|
|
42
|
-
| | Intel Mac Builds | build on and distribute to intel macs
|
|
43
|
-
| | API Parity | Accelerate development of Electrobun apis and native integrations to enable apps to migrate from Electron and Tauri
|
|
44
|
-
| | Windows support | build for and distribute to Windows
|
|
36
|
+
| | Milestones | Description |
|
|
37
|
+
| :-- | :-------------------- | :-------------------------------------------------------------------------------------------------------------------------------------- |
|
|
38
|
+
| ✅ | Core Architecture | Ship a working proof of concept with most of the core architecture wired up |
|
|
39
|
+
| ✅ | Packaging and signing | Packaging and code signing for MacOS |
|
|
40
|
+
| ✅ | Shipping updates | Integrated auto-updator |
|
|
41
|
+
| ✅ | Webview Tag | Cross browser electrobun implementation of the <webview> tag that electron has, for isolated nested webviews |
|
|
42
|
+
| ✅ | Port co(lab) | Harden implementation and enough electron parity to migrate <a href="https://colab.sh">https://colab.sh</a> from Electron to Electrobun |
|
|
43
|
+
| | Custom Web Runtime | Optionally use a cross-platform web runtime (Chromium) instead of the system's native webview |
|
|
44
|
+
| | Intel Mac Builds | build on and distribute to intel macs |
|
|
45
|
+
| | API Parity | Accelerate development of Electrobun apis and native integrations to enable apps to migrate from Electron and Tauri |
|
|
46
|
+
| | Windows support | build for and distribute to Windows |
|
|
45
47
|
|
|
46
48
|
## Contributing
|
|
47
49
|
|
package/bun.lockb
CHANGED
|
Binary file
|
package/dist/bsdiff
CHANGED
|
Binary file
|
package/dist/bspatch
CHANGED
|
Binary file
|
package/dist/webview
CHANGED
|
Binary file
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
## Project Structure
|
|
2
|
+
|
|
3
|
+
<pre>
|
|
4
|
+
/src - electrobun's src code
|
|
5
|
+
/src/browser - typescript compiles to the in-webview electrobun javascript api
|
|
6
|
+
/src/bun - typescript compiles to the main process javascript api
|
|
7
|
+
/src/objc - c-abi wrapped objective c, compiled to a static lib
|
|
8
|
+
/src/zig - zig native bindings, compiles to the native renderer process.
|
|
9
|
+
/src/zig/build - where the compiled src/objc ends up so zig can see it and embed it
|
|
10
|
+
/src/cli - a cli for building and running developer apps, it reads electrobun.config files
|
|
11
|
+
/example - Interactive example using the library.
|
|
12
|
+
</pre>
|
|
13
|
+
|
|
14
|
+
## Building
|
|
15
|
+
|
|
16
|
+
Tldr;
|
|
17
|
+
|
|
18
|
+
- clang to compile objective c wrappers for macos in src/objc (.m files) into a static library, since objc is a superset of c the wrappers have intentionally been designed with c-compatible wrappers/apis
|
|
19
|
+
- zig is built with zig's build system. must specify zig equivalent types for objc wrappers to map memory
|
|
20
|
+
- electrobun in-webview-api that runs in all frames of the webviews is built using bun with a browser target
|
|
21
|
+
- the in-webview-api and objc are built into src/zig/build/ so zig can see it
|
|
22
|
+
|
|
23
|
+
## Working on Electrobun
|
|
24
|
+
|
|
25
|
+
There are some npm scripts to facilitate building everything from the objc, zig, bundling webview api, transpiling the bun api and so an, as well as building the example app and executing it.
|
|
26
|
+
|
|
27
|
+
The example app is meant to be an interactive example of Electrobun's functionality, it's useful when implementing new functionality in any part of Electrobun to have everything rebuilt so you can interact with it in the example app which then doubles as a demo app for developers wanting to explore what Electrobun can do.
|
|
28
|
+
|
|
29
|
+
You currently need zig installed globally, and to be on an ARM mac. I dunno if you have to install xcode or xcode tools to get clang on your system. Will iron out a better dev flow in the future.
|
|
30
|
+
|
|
31
|
+
For now you can simply
|
|
32
|
+
|
|
33
|
+
1. clone the repo
|
|
34
|
+
2. in the repo root run `bun run dev:example`
|
|
35
|
+
|
|
36
|
+
If you take a look at the repo's package.json as well as example app's package.json and electrobun.config you'll get a better sense of what's happening for each step.
|
|
37
|
+
|
|
38
|
+
## How Developer apps are built
|
|
39
|
+
|
|
40
|
+
> Note: in order for an application to get keyboard focus on macos you can't run it as a subprocess of the terminal which greedily steals keyboard input, so it needs to be built into an app bundle.
|
|
41
|
+
|
|
42
|
+
This part is wip, but currently we create a minimal macos app bundle and execute it. There is a launcher shell script which calls bun with your typescript. It configures stdout/err to write to a named pipe log file and starts listening to it so you get the output in the terminal.
|
|
43
|
+
|
|
44
|
+
You can cmd+c to stop that, but for now to quit your running app you have to close the window.
|
|
45
|
+
|
|
46
|
+
A better dev flow, as well as installing bun to a global location outside the app bundle is being actively developed.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Website
|
|
2
|
+
|
|
3
|
+
This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.
|
|
4
|
+
|
|
5
|
+
### Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
$ yarn
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Local Development
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
$ yarn start
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
|
|
18
|
+
|
|
19
|
+
### Build
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
$ yarn build
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This command generates static content into the `build` directory and can be served using any static contents hosting service.
|
|
26
|
+
|
|
27
|
+
### Deployment
|
|
28
|
+
|
|
29
|
+
Using SSH:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
$ USE_SSH=true yarn deploy
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Not using SSH:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
$ GIT_USER=<Your GitHub username> yarn deploy
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
slug: electrobun
|
|
3
|
+
title: Meet Electrobun
|
|
4
|
+
authors: yoav
|
|
5
|
+
tags: [electrobun]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Earlier this year I was just wrapping up a beta of [co(lab)](https://colab.sh) a hybrid web browser + code editor for deep work. Mostly written in Typescript, SolidJS, and Tailwid. I'd been building it in Electron and after figuring out how to get code signing and notarization working, how to distribute it and so on I ended up with a distributable that was 80MB+ compressed.
|
|
9
|
+
|
|
10
|
+
I'd added an update mechanism as well (from yet another separate project) that was supposed to be the gold standard that uses blockmap technology. This segments your next version into blocks and lets you only download the blocks you need when an update is available. It does this on the uncompressed version of your app which in my case was over 150MB+. However if you happen to make a change that affects a part of your app at the beginning, even if it's only a single character, then all the blocks will shift with different checksums meaning each of your users will likely have to download almost 150MB.
|
|
11
|
+
|
|
12
|
+
I started multiplying 150MB by the number of users and multiplying that by the number of times I wanted to ship an update. I wanted to ship like the web—continuously—but the sheer amount of data I would have to distribute with every small app change was obsene. I'm bootstrapping [Blackboard](https://blackboard.sh) and I found myself having to hold back on updates and ship less frequently to avoid spending hundreds of dollars in S3/Cloudfront bandwith costs.
|
|
13
|
+
|
|
14
|
+
I had been kicking around the idea of building an Electron alternative with [Bun](https://bun.sh) since long before Bun hit their 1.0.0 and having to second guess how often I ship while trying to bootstrap a startup lab was just the motivation I needed.
|
|
15
|
+
|
|
16
|
+
So I picked up zig, C, C++, and Objc and got to work. Once I'd built enough functionality into Electrobun I ported co(lab) from Electron to Electrobun. The compressed distributable for the Electrobun version of co(lab) is only 18MB. That's more than a 4x reduction, but I wasn't satisfied with that. I ported BSDIFF from C to zig, optimizing it for speed with SIMD and some other tricks I came up with and added a built-in update mechanism in Electrobun. Now when users download updates they only need to download a patch file. A small copy change now generates a 14KB patch file. So from up to 150MB with Electron's blockmaps to 14KB patch file that's a 95% reduction in the size of updates.
|
|
17
|
+
|
|
18
|
+
After 20 years at small startups and unicorns, and spending so much time earlier in my career with Adobe Flex/AIR, being able to ship desktop apps in Typescript with a batteries included framework at the speed of the web is just the thing I've always wanted.
|
|
19
|
+
|
|
20
|
+
Next steps for Electrobun are to upgrade the Bun and Zig versions, support distributing your apps to Windows and Linux, and enable more functionality like shipping a cross-platform web renderer instead of relying on the system's webview.
|
|
21
|
+
|
|
22
|
+
Technically Electrobun is the first thing I'm shipping from my startup lab [Blackboard](https://blackboard.sh). I hope you like it as much as I do.
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
## Introduction
|
|
2
|
+
|
|
3
|
+
Configure your Applications icons. These icons are used for the icon of your app in the app switcher and in the file system like on your Desktop or in the Applications folder.
|
|
4
|
+
|
|
5
|
+
### MacOS
|
|
6
|
+
|
|
7
|
+
The default location for the icon folder is in the root of your repo in a folder named `icon.iconset`. At minimum you should add a 1024x1024 png icon, but you can add other sizes as well for more control. [Read here](https://developer.apple.com/documentation/xcode/configuring-your-app-icon) for more details.
|
|
8
|
+
|
|
9
|
+
You can specify a custom path for the `icon.iconset` folder in your [electrobun.config](/docs/apis/cli/Electrobun.config) file.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
## Bundling Static Assets in your app
|
|
2
|
+
|
|
3
|
+
The `views://` schema in Electrobun provides a robust method for handling static assets, ensuring they are securely and efficiently managed within the application's bundle. This documentation explains how to use this schema to set URLs for new `BrowserWindow` instances, incorporate CSS and JavaScript into HTML, and bundle static assets via the `electrobun.config`.
|
|
4
|
+
|
|
5
|
+
### Overview of `views://` Schema
|
|
6
|
+
|
|
7
|
+
The `views://` schema is a custom protocol used in Electrobun to reference assets and files within the application bundle. This schema allows for a clean separation of application logic and resources, ensuring that static assets like HTML, CSS, and JavaScript files are encapsulated within specified views or components.
|
|
8
|
+
|
|
9
|
+
You can think of the `views://` schema as an alternative to `https://` so it can be used in the context of BrowserViews anywhere a normal url can be used and electrobun will securely map those paths to the static asset folder in your application bundle.
|
|
10
|
+
|
|
11
|
+
### Using `views://` in BrowserWindow URLs
|
|
12
|
+
|
|
13
|
+
You can use the `views://` schema to set the URL for a new `BrowserWindow()` in Electrobun. This method simplifies referencing bundled assets and enhances security by encapsulating resources.
|
|
14
|
+
|
|
15
|
+
#### Example Usage
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
const { BrowserWindow } = require("electrobun");
|
|
19
|
+
|
|
20
|
+
const mainWindow = new BrowserWindow({
|
|
21
|
+
width: 800,
|
|
22
|
+
height: 600,
|
|
23
|
+
title: "Main Window",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
mainWindow.loadURL("views://mainview/index.html");
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
In this example, `mainWindow` loads an HTML file located at `views://mainview/index.html`. This URL points to the `index.html` file within the `mainview` directory defined in the `electrobun.config`.
|
|
30
|
+
|
|
31
|
+
### Incorporating CSS and JavaScript
|
|
32
|
+
|
|
33
|
+
Using the `views://` schema, CSS and JavaScript files can be loaded directly within an HTML file bundled in the application.
|
|
34
|
+
|
|
35
|
+
#### HTML Example
|
|
36
|
+
|
|
37
|
+
```html
|
|
38
|
+
<!DOCTYPE html>
|
|
39
|
+
<html lang="en">
|
|
40
|
+
<head>
|
|
41
|
+
<meta charset="UTF-8" />
|
|
42
|
+
<title>Sample Page</title>
|
|
43
|
+
<link rel="stylesheet" href="views://mainview/style.css" />
|
|
44
|
+
<script src="views://mainview/script.js"></script>
|
|
45
|
+
<style>
|
|
46
|
+
div {
|
|
47
|
+
background: url(views://mainview/somebg.png);
|
|
48
|
+
}
|
|
49
|
+
</style>
|
|
50
|
+
</head>
|
|
51
|
+
<body>
|
|
52
|
+
<h1>Welcome to Electrobun</h1>
|
|
53
|
+
</body>
|
|
54
|
+
</html>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Here, `style.css` and `script.js` are loaded using the `views://` schema, pointing directly to the assets within the `mainview` directory.
|
|
58
|
+
|
|
59
|
+
You can also see a `views://` url used directly in css just like you'd use any `https://` url.
|
|
60
|
+
|
|
61
|
+
### Bundling Static Assets via `electrobun.config`
|
|
62
|
+
|
|
63
|
+
The `electrobun.config` file can be configured to bundle and manage static assets using the `views://` schema. This configuration ensures all necessary assets are included during the build process and correctly referenced within the application.
|
|
64
|
+
|
|
65
|
+
:::info
|
|
66
|
+
The property name for each view, in this case `mainview` can be anything you'd like. And you can specify as many views as you'd like. This maps directly to the path you would use when referencing a file so you can organize your assets.
|
|
67
|
+
:::
|
|
68
|
+
|
|
69
|
+
#### Configuration Example
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
"build": {
|
|
73
|
+
"views": {
|
|
74
|
+
"mainview": {
|
|
75
|
+
"entrypoint": "src/mainview/index.ts",
|
|
76
|
+
"external": []
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"copy": {
|
|
80
|
+
"src/mainview/index.html": "views/mainview/index.html",
|
|
81
|
+
"src/mainview/style.css": "views/mainview/style.css",
|
|
82
|
+
"src/mainview/script.js": "views/mainview/script.js"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
:::note
|
|
88
|
+
Notice that in the "copy" section the destination is `views/mainview/` which maps to the url `views://mainview/`.
|
|
89
|
+
:::
|
|
90
|
+
|
|
91
|
+
In the `electrobun.config`, the `views` section defines entry points for scripts, while the `copy` section specifies static assets like HTML, CSS, and JavaScript files to be copied to their respective directories in the build output.
|
|
92
|
+
|
|
93
|
+
### Summary
|
|
94
|
+
|
|
95
|
+
The `views://` schema in Electrobun provides a structured and secure way to manage and reference static assets within your applications. By configuring the `electrobun.config` appropriately and using the schema within your application code, you can ensure a clean, organized, and encapsulated asset management system.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
> Configure an html element to function as a draggable region allowing you to move the native application window by clicking and dragging on the element.
|
|
2
|
+
|
|
3
|
+
When building desktop apps with Electrobun a common pattern is to create a frameless window, sometimes with the traffic light (close, minimize, maximize) buttons overlayed with the html content. You would then use html and css to create a top-bar and set that top-bar to be a draggable region allowing you full control over the style of the window.
|
|
4
|
+
|
|
5
|
+
You can set any html element to be a draggable region.
|
|
6
|
+
|
|
7
|
+
### Step 1: Instantiate the Electroview class
|
|
8
|
+
|
|
9
|
+
```typescript title="/src/mainview/index.ts"
|
|
10
|
+
import { Electroview } from "electrobun/view";
|
|
11
|
+
|
|
12
|
+
const electrobun = new Electroview();
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Step 2: Add the draggable region css class
|
|
16
|
+
|
|
17
|
+
Insantiating `Electroview()` will configure any element with the `electrobun-webkit-app-region-drag` css class as a draggable area.
|
|
18
|
+
|
|
19
|
+
```html title="/src/mainview/index.html"
|
|
20
|
+
<!DOCTYPE html>
|
|
21
|
+
<html lang="en">
|
|
22
|
+
<head>
|
|
23
|
+
<meta charset="UTF-8" />
|
|
24
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
25
|
+
<title>My Electrobun app</title>
|
|
26
|
+
<script src="views://mainview/index.js"></script>
|
|
27
|
+
<link rel="stylesheet" href="views://mainview/index.css" />
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div class="electrobun-webkit-app-region-drag">
|
|
31
|
+
click here and drag to move this window
|
|
32
|
+
</div>
|
|
33
|
+
<h1>hi World</h1>
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|
|
36
|
+
```
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
## Introduction
|
|
2
|
+
|
|
3
|
+
Electrobun's custom webview tag implementation behaves similarly to an enhanced iframe, but with key differences in capabilities and isolation. It serves as a positional anchor within the DOM, communicating with a Zig backend to manage a distinct, isolated BrowserView. This separation ensures full content isolation from the host webview, enhancing both security and performance.
|
|
4
|
+
|
|
5
|
+
## Basic Usage
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<!DOCTYPE html>
|
|
9
|
+
<html lang="en">
|
|
10
|
+
<head>
|
|
11
|
+
<meta charset="UTF-8" />
|
|
12
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
13
|
+
<title>webview tag test</title>
|
|
14
|
+
<script src="views://webviewtag/index.js"></script>
|
|
15
|
+
</head>
|
|
16
|
+
|
|
17
|
+
<body>
|
|
18
|
+
<electrobun-webview src="https://electrobun.dev"></electrobun-webview>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Compatability
|
|
24
|
+
|
|
25
|
+
The Electrobun webview tag integrates seamlessly with any reactive JavaScript framework, such as React or SolidJS, allowing for dynamic interactions and updates without disrupting the isolation of the webview's contents.
|
|
26
|
+
|
|
27
|
+
The way the implementation currently works, the html element is just a positional anchor that reports its position and relays events to zig which manages a completely separate BrowserView and overlays it at the same coordinates within the window.
|
|
28
|
+
|
|
29
|
+
## How is this difffernt to Electron's webview tag
|
|
30
|
+
|
|
31
|
+
### Chrome plans to deprecate their webviewtag
|
|
32
|
+
|
|
33
|
+
Electron's webview tag is based on a Chrome feature/api designed for Chrome apps which has been deprecated since 2020. You can read about that on [Electron's Github](https://github.com/electron/electron/issues/34356) and in [Chrome's developer docs](https://developer.chrome.com/docs/apps/reference/webviewTag). The warning declares it "remains supported for Enterprise and Education customers on ChromeOS until at least Jan 2025" which is fast approaching.
|
|
34
|
+
|
|
35
|
+
It's unknown what Electron will do when and if Chrome actually removes webview tag support from Chrome.
|
|
36
|
+
|
|
37
|
+
Unlike Electron's reliance on Chrome's now-deprecated webview tag, Electrobun introduces its own robust implementation that does not depend on Chrome's lifecycle. This independence ensures longevity and stability for applications using Electrobun's framework, even as Chrome phases out its support.
|
|
38
|
+
|
|
39
|
+
### Electrobun's webview tag is a separate layer
|
|
40
|
+
|
|
41
|
+
Because Electrobun's webview tag implementation uses a div anchor and then positions a separate isolated BrowserView above the parent BrowserView there are some interesting edge cases where you may want to click on the parent document or do things within the parent DOM, so Electrobun provides various special methods for handling those situations. For example ways to mirror a screenshot of the webview tag's contents to the host's anchor and hide it or stream an image of the contents.
|
|
42
|
+
|
|
43
|
+
## Properties and Attributes
|
|
44
|
+
|
|
45
|
+
### src
|
|
46
|
+
|
|
47
|
+
**Type**: `string`
|
|
48
|
+
**Description**: URL of the web page to load in the webview.
|
|
49
|
+
|
|
50
|
+
### html
|
|
51
|
+
|
|
52
|
+
**Type**: `string`
|
|
53
|
+
**Description**: HTML content to be directly loaded into the webview, useful for dynamic content generation.
|
|
54
|
+
|
|
55
|
+
### preload
|
|
56
|
+
|
|
57
|
+
**Type**: `string`
|
|
58
|
+
**Description**: Path to a script that should be preloaded before any other scripts run in the webview.
|
|
59
|
+
|
|
60
|
+
### partition
|
|
61
|
+
|
|
62
|
+
**Type**: `string`
|
|
63
|
+
**Description**: Sets a partition to provide separate storage for different sessions, useful in multi-user applications.
|
|
64
|
+
|
|
65
|
+
### transparent
|
|
66
|
+
|
|
67
|
+
**Type**: `boolean`
|
|
68
|
+
**Description**: When set to true, makes the webview transparent, allowing underlying elements to be visible.
|
|
69
|
+
|
|
70
|
+
### passthroughEnabled
|
|
71
|
+
|
|
72
|
+
**Type**: `boolean`
|
|
73
|
+
**Description**: Enables or disables mouse and touch events to pass through to underlying elements.
|
|
74
|
+
|
|
75
|
+
### hidden
|
|
76
|
+
|
|
77
|
+
**Type**: `boolean`
|
|
78
|
+
**Description**: Controls the visibility of the webview.
|
|
79
|
+
|
|
80
|
+
### delegateMode
|
|
81
|
+
|
|
82
|
+
**Type**: `boolean`
|
|
83
|
+
**Description**: Activates a mode where input is delegated to the webview even when it is visually mirrored to another element.
|
|
84
|
+
|
|
85
|
+
### hiddenMirrorMode
|
|
86
|
+
|
|
87
|
+
**Type**: `boolean`
|
|
88
|
+
**Description**: Enables a mode where the webview is hidden and mirrored, allowing smooth interactions during transitions or animations.
|
|
89
|
+
|
|
90
|
+
### wasZeroRect
|
|
91
|
+
|
|
92
|
+
**Type**: `boolean`
|
|
93
|
+
**Description**: Indicates if the webview had zero dimensions at any point, used internally to optimize rendering and updates.
|
|
94
|
+
|
|
95
|
+
### webviewId
|
|
96
|
+
|
|
97
|
+
**Type**: `number`
|
|
98
|
+
**Description**: A unique identifier for the webview instance, automatically managed by the system.
|
|
99
|
+
|
|
100
|
+
### id
|
|
101
|
+
|
|
102
|
+
**Type**: `string`
|
|
103
|
+
**Description**: The DOM ID for the webview element, automatically set to ensure uniqueness.
|
|
104
|
+
|
|
105
|
+
## Methods
|
|
106
|
+
|
|
107
|
+
### callAsyncJavaScript
|
|
108
|
+
|
|
109
|
+
**Parameters**: `{ script: string }`
|
|
110
|
+
**Returns**: `Promise`
|
|
111
|
+
**Description**: Executes JavaScript code asynchronously within the webview and returns a promise with the result.
|
|
112
|
+
|
|
113
|
+
### canGoBack
|
|
114
|
+
|
|
115
|
+
**Returns**: `Promise<boolean>`
|
|
116
|
+
**Description**: Determines if the webview can navigate backward.
|
|
117
|
+
|
|
118
|
+
### canGoForward
|
|
119
|
+
|
|
120
|
+
**Returns**: `Promise<boolean>`
|
|
121
|
+
**Description**: Determines if the webview can navigate forward.
|
|
122
|
+
|
|
123
|
+
### on
|
|
124
|
+
|
|
125
|
+
**Parameters**: `event: WebviewEventTypes, listener: () => {}`
|
|
126
|
+
**Description**: Attach event listeners for webview-specific events such as navigation and loading.
|
|
127
|
+
|
|
128
|
+
### off
|
|
129
|
+
|
|
130
|
+
**Parameters**: `event: WebviewEventTypes, listener: () => {}`
|
|
131
|
+
**Description**: Detach event listeners for webview-specific events.
|
|
132
|
+
|
|
133
|
+
### syncDimensions
|
|
134
|
+
|
|
135
|
+
**Parameters**: `force: boolean = false`
|
|
136
|
+
**Description**: Synchronizes the dimensions and position of the webview with its anchor element in the DOM, optionally forcing an update.
|
|
137
|
+
|
|
138
|
+
### goBack
|
|
139
|
+
|
|
140
|
+
**Description**: Navigates the webview back to the previous page.
|
|
141
|
+
|
|
142
|
+
### goForward
|
|
143
|
+
|
|
144
|
+
**Description**: Navigates the webview forward to the next page.
|
|
145
|
+
|
|
146
|
+
### reload
|
|
147
|
+
|
|
148
|
+
**Description**: Reloads the current content in the webview.
|
|
149
|
+
|
|
150
|
+
### loadURL
|
|
151
|
+
|
|
152
|
+
**Parameters**: `url: string`
|
|
153
|
+
**Description**: Loads a given URL into the webview, similar to setting the `src` attribute.
|
|
154
|
+
|
|
155
|
+
### syncScreenshot
|
|
156
|
+
|
|
157
|
+
**Parameters**: `callback?: () => void`
|
|
158
|
+
**Description**: Captures and synchronizes a screenshot of the webview's contents, useful for visual mirroring.
|
|
159
|
+
|
|
160
|
+
### startMirroring
|
|
161
|
+
|
|
162
|
+
**Parameters**: `frameRate: number = DEFAULT_FRAME_RATE`
|
|
163
|
+
**Description**: Starts mirroring the webview's contents at a specified frame rate, optimizing for performance versus visual fidelity.
|
|
164
|
+
|
|
165
|
+
### stopMirroring
|
|
166
|
+
|
|
167
|
+
**Description**: Stops mirroring the webview's contents.
|
|
168
|
+
|
|
169
|
+
### clearScreenImage
|
|
170
|
+
|
|
171
|
+
**Description**: Clears any images set as the webview anchor's background, typically used in conjunction with transparency and mirroring modes.
|
|
172
|
+
|
|
173
|
+
### tryClearScreenImage
|
|
174
|
+
|
|
175
|
+
**Description**: Attempts to clear the background image of the webview anchor if conditions are met.
|
|
176
|
+
|
|
177
|
+
### toggleTransparent
|
|
178
|
+
|
|
179
|
+
**Parameters**: `transparent?: boolean, bypassState?: boolean`
|
|
180
|
+
**Description**: Toggles the transparency state of the webview.
|
|
181
|
+
|
|
182
|
+
### togglePassthrough
|
|
183
|
+
|
|
184
|
+
**Parameters**: `enablePassthrough?: boolean, bypassState?: boolean`
|
|
185
|
+
**Description**: Toggles the ability for mouse and touch events to pass through the webview.
|
|
186
|
+
|
|
187
|
+
### toggleHidden
|
|
188
|
+
|
|
189
|
+
**Parameters**: `hidden?: boolean, bypassState?: boolean`
|
|
190
|
+
**Description**: Toggles the visibility of the webview.
|
|
191
|
+
|
|
192
|
+
### toggleDelegateMode
|
|
193
|
+
|
|
194
|
+
**Parameters**: `delegateMode?: boolean`
|
|
195
|
+
**Description**: Toggles the delegate mode for input events within the webview.
|
|
196
|
+
|
|
197
|
+
### toggleHiddenMirrorMode
|
|
198
|
+
|
|
199
|
+
**Parameters**: `force: boolean`
|
|
200
|
+
**Description**: Toggles the hidden mirror mode, optimizing interaction during transitions or animations.
|