197 points · by ingve · 7y ago · 234 comments
* Adding new APIs was a huge pain in the ass, you had to write all of this ugly bridge code in Objective C, and the APIs ended up being super unnatural on the JS side. As a result, desktop integration wasn't done much since it felt like a "Black Magic" type thing. Writing new APIs in Electron is Just JavaScript, so you can make something much more natural.
* We could literally do fuck-all for people running old versions of macOS - you can't upgrade Safari on old machines, you just Get What You Get. For awhile, every YouTube video on older macOS versions had a pink shade to it. Users write in, "This is clearly wrong!" "Yep, but we can't fix it. Sorry."
* And big spoiler - WKWebView uses _basically_ the same amount of memory give-or-take a few MBs as Chromium. It's the content that sets the memory usage bar, not the host.
Secondly, you lose control of your application runtime environment version - need a new WKWebView version to ship a feature? Time to tell your customers to upgrade the app and their OS.
I’d maybe consider this to cheaply ship a feature inside a Mac app, but this really isn’t an option for like 99% of dev teams considering Electron.
It’s really not an option. That and you have to rebuild everything for Win/Linux builds. Just makes no sense.
Also you can’t ship your own updated WKWebView.
I can see why it might potentially be attractive in purely architectural terms, but I wonder if the “savings” meaningfully materialise in practice when so little pure native development occurs in C++ on iOS and Android.
Regardless, there’s still a complexity cost - unique native platform UI code is still unique native code, plus all the localisation, QA testing, etc, etc fun that will entail for an app the size of Slack.
It really doesn’t. A “Hello, World” WKWebView is a couple of megabytes. The same in an Electron app is hundreds of megabytes.
A lot of Slack's audience is captive - employees, contributors to open source projects that chose Slack as their social outlet, etc.
It would be faster and take much less RAM, specially when multiple Apps are open and they could use the shared library.
Also, now that Chromium is going to be part of Windows, the same would also be a good idea, I think.
1. It's cross platform
Don't have to deal with the fact that Safari is missing these 12 APIs or has different edge cases
2. It's stable after shipping Users get a new version only when you ship. If you use the native widget then users get a new (often broken) version on every update by a 3rd party (Apple/MS/Google). Example: chrome just deprecated autoplay. If that bubbled into apps your app just broke. Electron could do the same but if you're testing like a good dev that break wouldn't make it to users. You as a dev would find it locally, deal with it, and only after ship to users.
so, no personally I don't want a shared widget. that sounds like going back to DLL hell or worse, just broken stuff.As a matter of fact, Chromium's/Chrome's engine Blink was forked off from WebKit back in 2013. Current WebKit is Apple's not-quite-as-well-updated version of the engine in old Chrome.
They can't run on native frameworks. If native frameworks are updated old apps would break. If native frameworks aren't updated newer apps would break.
What you're asking was already tried with Adobe AIR and failed. Instead we need lighter alternatives to Node.js and Chromium.
eCos is prior work on OS side that made me always think of designing systems for easy stripping.
why?
would not existing static analysis/dependency pruning take care of it if someone had the time?
I don't see what would be 'novel' here from a theoretical point of view..
still a good project possibly though
(not production-ready but it might be soon good enough for really quick GUI prototyping using subset of web technologies - javascript + react + flexbox + styles)
HMR & react-devtools are already supported.
The bridge itself is API stable. evaluateJavaScript:completionHandler: isn't going anywhere.
So the question is whether it's okay to use a native web view while still bundling your own V8 + Node. That seems like an improvement to me!
Historically, this hasn't been the case. Apple loves to deprecate stuff (although, thankfully, they are a bit slower to remove it). Before WKWebView there was a "stable" WebView.
Aren't those fairly discrete areas with fairly different levels of work? Doesn't most of what's on NPM run in WebKit / Gecko these days, anyway, since people commonly deploy client-side?
Like…Chrome?
In principle that is doable. Not sure about 100% compatibility as only WebKit (particular version) is 100% compatible with WebKit (particular version here). Edge is gone in that fight. Mozilla is standing but is not 100% compatible.
None of the four bullet points actually address real issues. The security problem isn't that Google is bad at security (they're among the best really). The problem is that Javascript code is generally written with the expectation that it will run in a web browser's highly locked down security context. Performance is really the same issue: web apps are authored wastefully. For use cases where you visit a web page for a few minutes then leave that's fine, but when you then let that code run for hours with no sandbox you will inevitably hit perf issues.
Write native apps. If you can't afford that, just make a web page.
Unless you have a core feature that _can't_ be implemented in Electron for some reason (I guess you're writing a game or something similar?), or have some other mechanism for locking your users in, writing a native app in 2018 is just putting your employees livelihood at stake.
It's not cool or fair at all, sure, but hey, us Marxists were telling you this will always happen for over 150 years now, and y'all still acting surprised.
I didn't write this wasn't true; I wrote this didn't matter.
Edit: to expand on this a bit: sure, most of the throwaway Electron applications won't have much life in them. But they'll suck the oxygen out of the room and kill everything else first, then fail. So if there was any livelihood staked on those superior native apps you made — well, those people are looking for jobs now. Hope all of them have it as easy as a young software developer.
So the parent seems correct. Winamp stayed native an lost. Spotify embraced the rapid dev that using a browser host brings to app dev and won.
Square peg, round hole. Electron just gives you a hammer to make it fit anyway :)
No trickery, no hidden browser windows, just normal native executables.
Java also solves the cross-platform issue, though it's GUIs tend to not look native (As opposed to Lazarus above, which is native).
If you're impressed by a webserver being able to interact with the OS for things like accessing files or databases, your mind will be absolutely BLOWN when you learn real native development.
Thank you.
Java apps on the desktop became more prevalent and usable when Java was bundled in. The Electron is not so different from what worked for Java.
Plus it gets rid of visual clutter like the tab bar and treats your app like an actual application rather than a simple website for viewing.
People using desktop toolsets never even have to think about that "problem" because it just doesn't exist when you're using the right tools.
There are three types of tools for every job..
* The right kind
* The wrong kind
* The wrong kind but we'll make it work
Electron hits squarely in the third category by hiding the browser and webserver and pretending it's a real desktop application.
Cross-platform: yes, if you ignore the fact that there are only 2 browsers left, both being buggy and incomplete (as they've been for many years) and with no other implementation in sight, or even remotely feasibly for small to medium-sized companies or teams. Also they're so bloated and isolated from the native environment that you might just as well install a Linux virtual machine and call it a cross-platform UI.
No, thanks. I'll wait for a better cross-plattform UI solution.
In reverse, I would argue, Hundreds of "Native UIs", most of them obsolete or dead, have shown to be incapable to express cross-platform, flexible layout capabilities of 1990s HTML/CSS combo.
The most recent, yearly updated mobile OSes appear to be cooler, however we'll see in 10 years how they will end up.
But most haven't. If you want the capabilities of the HTML versions unable to even center vertically or requiring invisible images to format tables, there are plenty of UI to choose from. Qt, Wx are extremely capable nowadays.
Why not have libchrome or a libelectron that moves more slowly than chrome six week release cycle (maybe do 6 months) then have apps build to it and share the library.
No. It depends on the package manager. E.g: https://www.archlinux.org/packages/community/x86_64/electron...
A shared electron package used by a few different apps: see the "required by" column...
As electron gets more popular, this will be the standard in Linux distributions (at least historically thats how dependencies handled there), Windows has different standard (self contained everything) so there it is the normal way - everybody already used to it for decades...
If Electron apps would specify requirements instead of bundling the whole runtime, you will have to wait for the runtime to be downloaded the first time the app runs. You will still end up with multiple versions of the same runtime running on your system.
If you absolutely need to do web primitives inside your app, well then, html engines used to come in a few megabytes and no external deps. If your webcode needs the entire Chromium monstrosity bundled in order to run, someone has been doing something entirely wrong.
By choosing to go the Electron way, you're imposing a huge computational penalty on your users, just to make your life easier. Now multiply the overhead by the number of users, and that's how much electricity your decision just cost globally. This also manifests in frustration, like due to decreased battery life on laptops. And with enough popular software written this way, this pushes users to replace their perfectly good computers earlier than necessary.
(The lats point applies to web bloat even more; I'm really annoyed when a non-tech person asks me for help, because their computer "works slow, it must have viruses", only for me to discover that the computer is perfectly fine, it's just their favorite pages went through another rewrite and are now each 5x more bloated than they used to be.)
We can only defeat that by having another awkward "OS" in a VM which browser/electron is.
Native is awesome when you have the money.
It uses sciter (https://sciter.com) which is sort of micro-electron if you wish. Distribution of the app is 2mb rather than 200mb.
What do you think the cross-platform browsers you're packaging in Elecron are written in?!
The cross-platform browsers are written in a whole lot of platform-specific code.
FreePascal + Lazarus.
It's not only about GUI designer and fast cross-platform compiler.
And I say that as someone who was writing Pascal professionally ~5 years ago.
That to me is the biggest issue. There's "cross platform" and there's "cross platform".
QT gets you the major desktop platforms, but not a ton more.
The web gets you desktops, mobile phones, tablets, game consoles, TVs, car infotainment systems, even my fucking watch!
Obviously you aren't going to handle all of those without some custom code for a few platforms, but when the web is a target platform for a project at all, it's often worlds easier to just spend the time on improving the mostly single codebase rather than try to do multiple codebases. And I genuinely believe that outside of larger companies, having the whole company dedicated and focused on improving one codebase is going to end up with a better user experience than splitting those same resources up over several codebases.
If your app is desktop-oriented only, then Qt is such a fantastic system to work with! But it's increasingly rare that software targets desktop only.
It's not like browsers all got together and agreed on a standard API, literally every browser does things differently from the others.
Agreed. Seems like there is no alternative, though; what you said in your first paragraph definitely is not a comparable alternative except if you're handing out money my company could use to do what you suggest.
FPC + Lazarus, native executables, cross platform.
But it’s not like FPC/Lazarus is the only portable GUI solution — Qt, Fox, Swing, SWT, Gtk etc. also exist, and don’t require a fringe language (and I say that as someone who did Turbo/Borland Pascal and Delphi development for more than a decade). What Lazarus offers is a Delphi-type form builder tool, but that seems a lot less interesting in this day and age of heavily customized UIs that aren’t static grids of square components — in particular, we increasingly rely on responsive layouts and smooth animations between them.
Moreover, I’ve yet to see a FPC app (or any app for that matter that isn’t Electron or web) that doesn’t look like an old fashioned Windows-style GUI app. Do you have any examples?
Yes, there are many GUI toolkits, the LCL creates native applications while some others do not, but it's certainly not the only one.
It's the one I prefer so I use it as an example over QT, Swing, JavaFX, etc.
Lazarus form builder let's you create forms very quickly and easy, and OS themed design.
If you want other types of GUI designs you can do that too, though personally I prefer standard OS design.
As far as static grids and square components, I think you're looking at old stuff..
You can make things as squiggly as you like, and of course you can always use images and colors to design your GUI and let your imagination run wild, and it'll look entirely non-native.
Responsive design isn't that challenging either, use anchors and smart design.
I don't have any examples of desktop applications I've made, that look like web-apps, no, but I might make some after you giving me this idea, and I'll be doing it with FPC/Lazarus.
People gravitate to Electron not just because you can’t build cross-platform apps in it, but because the underlying UI tech is just the web. You can even do as Slack did, which is to offer the exact same app in the browser. You can’t do that with FPC/Lazarus. The latter is geared towards fairly static layouts, not the kinds of snappy, fluid, single-window apps that Electron is used to build. It’s just a very different world.
Nobody is doubting that you can build decent Windows-style apps with FPC/Lazarus, just as they’re not doubting that you can do it with Qt.
Random searches in "dice.com"(pick any job site you want) for "Pascal" yields 5 positions. "Python" yields 8,950. "C++" yields 6008. Even "8086 assembly" yields 1,378 jobs. "Java" yields 17,000+. There is a trend here if you care to see it.
You are obviously passionate about Pascal. That's awesome. Keep using it, and squeeze it for everything its' worth. Please don't be disheartened when technology moves on without you though, often in directions that feel "wrong" to us. Electron feels wrong to me, but it doesn't matter. Technology is going to move where technology is going to move, and sometimes you have to get on board with choices you dislike to avoid being left behind entirely.
PS: I cut my teeth on Pascal in the early 90's, and wish it had become more popular as well.
I'm using Node.js right now along with AWS for example, not my favorite combo but it's an appropriate solution being used as a webserver.
I've posted about FPC because it's one of the right tools for the job and the one I prefer over C/C++, Java, etc. for desktop applications.
I don't mind spreading the word about FPC, but really what I'm trying to push for is that there are appropriate tools for desktop development such as C, C++, Python, Nim, Go, Object Pascal, and a bunch more. I just happen to like and push for one of those.
Especially with the "benefits" for Electron like cross-platform deployments, are things that other languages such as Java or Object Pascal, also does and does pretty dang well.
For a benign example: using Google search
For a less benign example: your browser/device/network being tracked for ads when using Google search
Video explanation/demonstration: https://youtu.be/SWEts0rlezA
If I want to write a Mac-only app, I can do that in Objective-C/Cocoa, and be quite happy.
For Linux, native means fighting with primitive C and X11 or Gtk, etc., which I can do but I loathe it.
For Windows, I have no idea, C# maybe? I'd rather eat broken glass than install Windows and find[ed.] out.
So if I'm doing cross-platform, my current working choices are Electron, Java, FreePascal/Lazarus, or Scheme.
Electron's easy to build all three platforms on, performance is OK despite the bloated example of Slack.
Java would need to bundle the JRE everywhere, and I've been largely Java-clean for 10 years.
Lazarus is semi-broken on Mac currently, only 32-bit like stone age tools, Cocoa port is unfinished. Maybe they'll get their shit together someday, I like it when it works.
Scheme native binaries are hard and experimental, but getting better.
Using a WKWebView on Mac, then writing a completely different wrapper on Linux & Windows, is unacceptable for my uses.
So my actual shipping code is Electron.
Maybe devs instead of being lazy suckers could start to worry about this aspect.
It is neither a hammer nor a nail, it just works for some specific purposes.
However on macOS it is missing one important feature (to me at least) that used to work with WebView:
You can't capture the image of the web browser window any more.
You used to be able to go something like:
NSBitmapImageRep *bitmapdata = [view bitmapImageRepForCachingDisplayInRect: bounds];
[webView cacheDisplayInRect: bounds toBitmapImageRep: bitmapdata];
Or: [NSView cacheDisplayInRect:(NSRect)rect toBitmapImageRep:(NSBitmapImageRep *)bitmapImageRep]
But that's a synchronous API, and since WkWebView runs in another process, it requires a remote procedure call, so Apple simply returns a blank image from that call now.https://stackoverflow.com/questions/31969950/wkwebview-cache...
I think the iOS way of capturing a screen snapshot from WkWebView still works, though, but I can't remember off the top of my head...
However, Apple added a new method to Safari, but last time I checked it was only in the beta Safari and not supported in the version installed on the operating system. (When you make a WkWebView it uses some specific framework that's not necessarily the latest beta version of Safari you've installed.)
//iOS func takeSnapshot(with snapshotConfiguration: WKSnapshotConfiguration?, completionHandler: @escaping (UIImage?, Error?) -> Void)
//macOS func takeSnapshot(with snapshotConfiguration: WKSnapshotConfiguration?, completionHandler: @escaping (NSImage?, Error?) -> Void)
But the problem with this method is that it takes a totally different rendering path ("this is a software painted snapshot"), so some stuff may look different, and WebGL stuff doesn't appear, and it's a whole lot slower than cacheDisplayInRect used to be).
https://stackoverflow.com/questions/46842384/wkwebkit-takesn...
This bug describes the problem and the issues and the less-than-ideal solution:
https://bugs.webkit.org/show_bug.cgi?id=161450
Summary: [Cocoa] No reliable way to get a snapshot of WKWebView
- no screenshots
- no printing
- no user stylesheets
- no cmd-F find
- no delegate method for hover-over-link
- no access to container NSScrollView (on macOS)
- harder to customize context menu (AFAICT)
- ignores URLProtocols (10.13 added a new way to implement custom protocols for WKWebViews with a completely different interface than NSURLProtocol/WebView)
I'm dreading the day when Apple is going to require me to 'upgrade' my WebView to WKWebView.
All I want to do is supply a byte stream containing HTML, and have it displayed in an NSView, with standard features. This doesn't seem like an obscure case, or a difficult problem. I don't understand why none of Apple's web views ever had simply a load(stream:NSInputStream) method. This was hard with WebView, and WKWebView made it a lot harder.
But breaking up the browser into different processes and communicating via messages and sharing textures in GPU memory between processes (IOSurface, GL_TEXTURE_EXTERNAL_OES, etc) is the inextricable direction of progress, what all the browsers are doing now, and why for example Firefox had to make so many old single-process XP-COM xulrunner plug-ins obsolete.
IOSurface:
https://developer.apple.com/documentation/iosurface?language...
https://shapeof.com/archives/2017/12/moving_to_metal_episode...
GL_TEXTURE_EXTERNAL_OES:
https://developer.android.com/reference/android/graphics/Sur...
I'm sure for some use cases it's "progress" but I'm really having trouble seeing it right now. It would be an improvement if I were writing a web browser but I don't understand why it had to make the simple case worse.
And so the results look cheap.
But as far as I understand it, there's a bit of a fatal problem going forward on iOS, last time I looked at it a year or so ago (I'd be thrilled if they've come up with a way to address this problem):
The iOS NativeScript bridge uses the old deprecated UIWebView and JavaScriptCore's Objective C integration stuff that lets you directly call back and forth between Objective C and JavaScript.
However, that Objective C bridging stuff is not supported on WkWebView, since it runs in a separate process, and has a different way of sending messages to the web browser, but not calling native code directly or passing pointers to objects or buffers in memory.
Why would you want to do that? To get direct access to an array of binary floating point numbers, or the pixels of a canvas or WebGL texture, instead of converting to and from JSON, or serializing images as data urls with base 64 encoded png files, for example. (Yech!)
You can send messages back and forth to WkWebKit, but that's vastly less performant than the direct calling UIWebKit JavaScriptCore bridging stuff, which operates in the same process and memory space.
And the NativeScript iOS integration layer is totally dependent (built on top of) on the way the JavaScriptCore bridging stuff works, and would have to be completely rewritten from scratch (and be much less efficient and require a lot more plumbing on both sides), in order to support that kind of out-of-process messaging to WkWebKit.
The great thing about NativeScript is that gives you has such an efficient high bandwidth interface to native code from JavaScript. But it just necessarily uses an old crappy JavaScript engine with no JIT.
One of the best thing about using WkWebKit is that the Just In Time compiler is enabled, so it's blazingly faster than running JavaScriptCore in the same process (which has it disabled, since non-Apple apps aren't allowed to write to code memory).
Of course it depends on how much of your application is written in JavaScript and would benefit from the JIT, and how much it depends on calling and sending data back and forth between native code and JavaScript. But the NativeScript way of doing things makes many assumptions that would make it very slow with RPC messaging instead of direct calling.
PhoneGap/Cordova is fine using WkWebKit because it uses a JSON messaging interface in the first place, not the more efficient higher bandwidth Objective C bridging stuff. It's JavaScript/Objective C bridge is much simpler than NativeScript, and people don't use it the same way that NativeScript is designed to be used.
NativeScript, as cool and amazing as it is, is deeply tied to old technology on iOS, JavaScriptCore and UIWebKit.