Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Capacitor: Cross-platform native runtime for web apps (capacitorjs.com)
116 points by thunderbong on Oct 30, 2021 | hide | past | favorite | 47 comments


Capacitor creator and co-founder of Ionic here (company that owns and works on Capacitor).

If you aren't familiar with Capacitor, it's a way for web devs to build cross-platform apps using standard web technology and any popular web stack. For example, you can build mobile apps using popular stacks like Next.js + Tailwind as in this example: https://github.com/mlynch/nextjs-tailwind-ionic-capacitor-st....

We've got some exciting things in the pipeline like a Project API for automating configuration (whitelabling/CI/etc), E2E testing, easier native HTTP features, resource generation (splash/icon/etc).

Happy to answer any questions about Capacitor!


Capacitor puts all APIs in the same context and thread as the UI. Something that Electron did a long long time ago before realizing the security implications.


You are correct that Capacitor plugin API entry points are in the same thread as your web/UI code (which will run in a separate process from your native plugin code given WKWebView sandboxes your app in a separate process. They communicate through message passing only). I don’t think it’s directly comparable to Electron for a few reasons. What Capacitor is doing is more like adding new Web APIs to the browser. You have full control over which of those APIs are exposed and they are all backed by the native sandboxing and permission model available on each platform. Additionally you are almost always only loading trusted local content. Electron exposing node runtime to untrusted remote content running in unsandboxed win32 apps, for example, is a pretty different beast. We do take security seriously though and would be happy to review or consider how we can enable users to lock down their apps even more.


Electron apps, like Capacitor app, are trusted content. This is a red herring.

However, both can have a bug that exposes XSS and give direct access to all the nice APIs both add.

For example, adding a SQLite plugin gives the attacker full access to all local db data for the app. Or node APIs vs FileSystem APIs.

The solution to have have two threads and let the dev specify their own API to communicate.

Electron had bad solutions for a while but it’s gotten better these days and might offer some ideas

I’m a fan of your work improving the stalled Apache product and moving it forward as Capacitor. I use it! v2 though, as I haven’t upgraded to v3. Maybe I’ll try that this weekend.


Appreciate the feedback and insights! Definitely more we can do there and will see about incorporating more of their techniques


What do you mean exactly? Could you give an example?


XSS gain access to native API


I am very happy using ionic, stencil and capacitor! You are really doing a great job, thank you!


How does this compare to React Native from a build-tool persepctive? From experience Native, Cordova, Xamarin, etc, all took a while for their build-tools to mature (mostly by making the right trade-offs) so to allow a degree of freedom without running into some build hells (though sometimes still do). It's for this reason that I normally just go plain objc/swift/java


The answer is nuanced because a good chunk of your app is just your web app, so you use standard build/dev tools there. For the native side, Capacitor probably has the least amount of abstraction over native compared to Xamarin or RN, it’s quite a bit simpler than both of those. We have some CLI commands to run your app locally but otherwise you just use Xcode or Android Studio directly, no need for a lot of custom brittle tooling


I see! Thanks for the info. One of my concerns is more about extendability & language-bridging;

eg my app needs to access a bluetooth module or uses opencv: would it be easy to plug in an existing Swift/Java libraries that has deps on these low-level stuff (without mingling too much with the build process like enabling or turning off some flags, hijacking some of Capacitor's own build processes, etc)


Absolutely. If it’s not in a Capacitor plugin and it’s custom native code or config, you manage those things as you would any other native iOS or Android project. On iOS just add it to your Podfile or add the library in Xcode. In Android add it as a dependency. We have some automated configuration tooling coming if you really don’t want to touch the IDEs at all: https://github.com/ionic-team/capacitor-configure/


thanks! very cool to know! I'll try out Capacitor in my project!


Some of those things in the pipeline like wkwebview-friendly HTTP sound great, would we be able to more easily see requests in the browser Dev tools for instance (a la native browser fetch)? Also can we expect any perf improvements over Cordova (I assume rendering perf would be identical)?


Whats the usecase of capacitor vs using a tool like pwabuilder.com to deploy pwas to the app stores?


Capacitor let’s you add any native functionality that you need to create your full native app experience. Also keep in mind you can’t just wrap a PWA and expect it to be accepted into the App Store without adding some additional native functionality which Capacitor provides


Hey! React Native developer here.

What advantages do you think Capacitor has over React Native?


One of the biggest ones is you can use any web technology, and even plain React. Most React development actually happens with react-dom today so you can bring those apps and that code to mobile through Capacitor.

Ultimately Capacitor is the most true to web development of the alternatives out there, so if that matters to you it’ll be better on that front.

It’s also a lot simpler than RN and feedback has been there’s a lot less upgrade hell with Capacitor


Capacitor user here (with Mithril/Typescript). It's OK for what it does but everything feels very fragile and I get freaked out anytime I have to touch the Android or iOS code for fear of breaking it. The plugin ecosystem is also a bit of a quagmire of abandoned repos and figuring out if you can still use things from Cordova without too much fuss.

I tried going the TWA route for the Play Store but there isn't an IAP solution yet (and I can't use Stripe because...). I look forward to not needing Capacitor in the future, but for now it mostly stays out of the way.


> everything feels very fragile and I get freaked out anytime I have to touch the Android or iOS code for fear of breaking it. The plugin ecosystem is also a bit of a quagmire of abandoned repos

That is exaclty how I feel about my RN app ;-)


Maybe I've just been doing this too long but my first reaction was "Another one??"


Capacitor has been around for a while, at least for a couple of years. I think it's the Ionic team's response to the EOL for Cordova/Phonegap.

I've been stung by ionic/drifty a couple of times, but I really hope this project survives. There are some great ideas here.


Recently I had to rebuild an iOS app originally built in Ionic2 / Cordova 4.5.

I was pleasantly surprised it basically built in one go on a fresh MacOS install with the latest Ionic and Cordova 6.5.

I didn't expect that.


Sorry you've been stung before! Capacitor is definitely here to stay. The project has been taking off recently and is powering the majority of apps for our users and customers today. Also we're starting to see more platforms that used to be powered by Cordova start to switch to Capacitor so that should further solidify its staying power.


It's a shame that the rules are so convoluted for the App and Play stores.

Otherwise you could make a "App Director" app and then just have people use your web app. As native functionality is needed it will delegate to the "App Director" app. Perfect example being notifications and interfacing with things like the calendar and contacts.

This sort of app wouldn't be allowed on both stores.


Why would it not be allowed on Google Play?


I develop and maintain a relatively popular open source Svelte[1] template (w/ live reload!) to develop cross platform apps.

Capacitor really is a beauty to work with. While I disagree on some design decisions (putting build platforms at the root of the directory for one) the overall ecosystem is quite healthy and strong, and while backwards compat with Cordova is hit or miss, its quite good for a tool thats a decade old.

[1]. https://github.com/drannex42/svelte-capacitor


How does this compare with NativeScript? I know it can work with capacitor but unlike ionic it complies down to actual native UI and not mostly web views, is capacitor Ionics answer to just being glorified web views?


There were a bunch of mostly positive comments about Capacitor in yesterday's PWA Builder discussion if you want to compare the two: https://news.ycombinator.com/item?id=29040793


1F or 1pF ? I wish that people will be more creative when choosing names for their pet projects. It really helps when searching.


I'm confused between Capacitor and Ionic. If possible can anyone explain the difference between these two?


Anyone using this care to weigh in with pros/cons/comparisons?


Not a direct answer to your question but this was a great write up from the BBC (they use Capacitor): https://medium.com/bbc-design-engineering/shipping-progressi...


Their docs have a comparison with Cordova here: https://capacitorjs.com/docs/cordova


I’ve made 3 apps with Ionic and Capacitor (2 released, one large that I abandoned).

While it’s great the enormous draw back is reliance on crappy community plugins and using old Cordova stuff to access native features.

They have nice premium stuff behind the enterprise paywall but they don’t offer prices and make it pretty clear that they’re not interested in speaking to a small indie dev.

I eventually abandoned my “big” project on Ionic due to this issue. This was about a year ago.

I looked at React Native and that seems to at least have more options but I’m not sure if it will be better.


The two biggest advantages of RN in my mind are that it has no paywalled content like Ionic/Capacitor and that the ecosystem is very very active, very Soldom do you run across "crappy community plugins" like you will with Cordova/Capacitor/etc. Sure there are many "crappy plugins", but there's almost always a much better option to those.


I know developers are allergic to paying for anything but if you're a company working on a really critical app, the reality is Ionic and Capacitor offer something you just can't find in any other mobile ecosystem today: direct support and officially-supported enterprise integrations. The premium features we have are almost all enterprise-focused ones that indies and startups frankly just don't have a lot of need for or they already have community-supported options. Our approach there is to monetize things that are "must have" for enterprise but only "nice to have" for everyone else. If they are "must have" for everyone we try to make those free. And you can actually call us and get dedicated support. Can you imagine Facebook or Google ever doing that?

With that revenue we are able to invest back into the OSS technology and we're also aligned with actual users of the stack. This isn't an internal project at a big tech company that we just happened to OSS for goodwill but only build for ourselves. At the end of the day our users are our #1 focus, not internal projects.

Capacitor is younger than RN but the ecosystem is growing around it and I've been excited seeing more 3rd party vendors officially support Capacitor (Sentry, for ex) and the quality of the first-class Capacitor plugins has gotten a lot better this year (and we've also chipped in to help where we can).

Capacitor has a huge addressable market since all web technologies work with it and I think that will help it become a pretty big force in mobile. People don't realize this but Cordova powers a lot more apps than both RN and Flutter today. There's just a ton of web devs in the world.


You come across very defensive in this post which indicates that I maybe hit a nerve (or I’m reading it wrong).

Either way, your enterprise stuff looks great but you give no indication of pricing and as a dev I’m not allergic to paying for things but I am allergic to companies who don’t have an “other than enterprise” story.

I would happily pay you a monthly fee to get access to plugins that are better than the community dross available but you’re not interested in my business.

I think Capacitor and Ionic are great, sadly Ionic the company leave much more to be desired.

I once asked a question somewhere in the forums about a good plugin for something and the response was “hey, we don’t offer that to none enterprise customers but feel free to make your own plugin and share with the community” - sure, I’ll get right on that - if I wanted to be a native dev I’d be a native dev


Not defensive, apologies if it came across that way. I try to explain how Ionic is different because developers often aren't thinking about some of these non-technical/support things, but their boss or team leads might be. Everything is very "free" on the client-side of mobile but that has also created a situation where teams building really important apps aren't able to get any dedicated support or guarantees around maintenance, so we're trying to fill that gap.

We've made our pricing more transparent recently and have added special plans for indies and startups that qualify as well. In particular we're trying to make more of our enterprise native plugins accessible for startups: https://ionic.io/pricing


How come all top level comments are from the same time? ( for me, now, 47 minutes ago )


I think it's a HN feature related to a post with existing comments being boosted to the frontpage by a moderator. The timestamps of both the post and the existing comments are faked for a time period to appear consistent with the time of the boost rather than the original post.

I.e. all the comments were not posted at the same time just now, but over a longer time period hours ago.


That's a really interesting observation!

To be fair, there's only 4 top-level comments from that same time. Given a big enough audience it's reasonable to think that this would happen from time to time.

There doesn't appear to be any particular bias / agenda from the posts (that I can see) so I'm guessing it's just coincidence.


Ah, it seems to be a submission from the second hand pool ( https://news.ycombinator.com/pool ).

That would make sense, as it popped up on the FP?


Web Native Apps?


Yeah, this was made by the team behind ionic...which has a long history Of trying to twist words in their favor and sell their framework.

Personally,it's just Cordova in a different suit and isn't remotely related to what native means on mobile. The entire reason they are selling their framework so hard is under the enterprise tab in the menu.


It's not just Cordova in a different suit. There are a lot of similarities, but there are some pretty big differences. For example, Capacitor has first-class support for Progressive Web Apps and can be used as a library you link with that comes with an abstracted set of APIs for accessing native/device features on iOS/Android/Desktop/Web with the same codebase. There are a ton of small decisions that all add up to a pretty dramatically different experience and our Web Native moniker represents our focus on building an app that is native to the web and then running it on all the platforms you care about with full access to the native features you need on each platform.

And don't just take my word for it, the feedback from actual users is that the experience is dramatically better than Cordova. For example, see the 2020 State of JS survey results: https://2020.stateofjs.com/en-us/technologies/mobile-desktop...

Also on the Enterprise tab, the other way to look at this is we have a sustainable revenue and funding model for the project that is aligned with actual users of the project (as opposed to this being an internal project we just happened to OSS for goodwill/hiring benefits). I'm really proud of that and consider it a huge advantage of the project.


Here is an alternative I've used for years: https://gonative.io/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: