惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog RSS Feed
W
WeLiveSecurity
I
InfoQ
L
Lohrmann on Cybersecurity
Simon Willison's Weblog
Simon Willison's Weblog
腾讯CDC
S
Schneier on Security
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threat Research - Cisco Blogs
P
Palo Alto Networks Blog
Attack and Defense Labs
Attack and Defense Labs
I
Intezer
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
S
Securelist
T
Tailwind CSS Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
T
Tor Project blog
博客园 - 叶小钗
Engineering at Meta
Engineering at Meta
Microsoft Security Blog
Microsoft Security Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
Apple Machine Learning Research
Apple Machine Learning Research
V
Visual Studio Blog
Know Your Adversary
Know Your Adversary
T
The Blog of Author Tim Ferriss
N
News and Events Feed by Topic
小众软件
小众软件
G
Google Developers Blog
F
Full Disclosure
O
OpenAI News
The Last Watchdog
The Last Watchdog
G
GRAHAM CLULEY
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
Jina AI
Jina AI
S
SegmentFault 最新的问题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
Y
Y Combinator Blog
N
News and Events Feed by Topic
K
Kaspersky official blog

StackBlitz Blog

Cloudflare is now backing pkg.pr.new’s data infrastructure! Bolt 100K Open Source Fund ViteConf 2024 was a blast Unbundling the JavaScript ecosystem StackBlitz is joining the Open Source Pledge Announcing TutorialKit: Interactive tutorials in the browser Get ready for ViteConf 2024 Announcing pkg.pr.new StackBlitz welcomes Ari Perkkiö, core team member of Vitest Catch us at Figma Config WebContainers and the future of web dev (interview with Jòan Varvenne) Open Source at StackBlitz Avoiding CORS issues with this one simple trick How to document design system components What is Vite (and why is it so popular)? Improving the developer experience of enterprise design systems Flow state: Why fragmented thinking is worse than any interruption What is Storybook? An Overview for Developers The Self-Rendering Eval Shirt Starters Upgrade: WebContainers and Vite Putting the Dev in Figma’s Dev Mode Announcing StackBlitz Self-hosted Building Together in Illinois 5 lessons design systems teams can learn from open-source maintainers Announcing Native Language Support in WebContainers Introducing StackBlitz Teams ViteConf is back! Bringing Sharp to WebAssembly and WebContainers npm, yarn and pnpm are now supported natively in WebContainers The Atomic Waltz: Unraveling WebAssembly Issues in V8 and SpiderMonkey Now I am become the Destroyer of Threads WebContainer API is here. StackBlitz September 2022 Update StackBlitz August 2022 Update StackBlitz July 2022 Update Introducing: Collections and Social Previews! Down the caching-hole: adventures in Announcing ViteConf StackBlitz June 2022 Update The Fox and the Bolt: Bringing WebContainers to Firefox WebContainers are now supported in Firefox on desktop and Android StackBlitz May 2022 Update StackBlitz April 2022 Update Cloudflare and StackBlitz partner to bring Cloudflare Workers to your browser Powering over 2M developers a month, StackBlitz has raised $7.9M StackBlitz March 2022 Update Announcement: WebContainers are out of beta in Chromium StackBlitz has joined the Bytecode Alliance StackBlitz February 2022 Update Bringing WebContainers to all Browsers: a call to action for COEP Credentialless Cross-Browser support with Cross-Origin isolation StackBlitz welcomes Patak, core maintainer of Vite Chasing Memory Bugs through V8 and WebAssembly Remix v1 has landed, and it runs on WebContainers SvelteKit is now fully supported in WebContainers We Shopify partners with StackBlitz to bring Hydrogen development in-browser StackBlitz September 2021 Update Introducing Vite.new Templates! Announcing WebContainers Astro support! 🛰 Introducing: SQLite3 support in WebContainers! 🧪 StackBlitz July 2021 Update StackBlitz June 2021 Update Introducing WebContainers: Run Node.js natively in your browser Interactive Docs: The new norm for Remote Work
WebContainers now run on Safari, iOS, and iPadOS
Sylwia Vargas · 2023-04-13 · via StackBlitz Blog

We are finally able to let you in on a secret: in January we successfully ran the first WebContainer projects on Safari. Today we are excited to announce that

WebContainers run on Safari, iOS, and iPadOS 🥳

Starting with iOS 16.4, you can enjoy the interactive code examples and playgrounds right from an iPhone or iPad.

WebContainers working in Safari!

Safari support is now in beta, and we’d love to extend a warm invitation to you to try running a Node.js app in WebContainers on your iPhone or iPad and let us know what you like, don’t like, and what bugs you find 💙

Building for the stable future

StackBlitz was created with the mission to build the web with the web. This was a futuristic idea and as such, it required tools of the future.

StackBlitz was built to be shockingly fast, and to accomplish this we needed to hack and leverage emerging technologies. Two years ago, we laid Wasm threads at the foundation of WebContainers. Even today, the threads are still yet to become a standard. Similarly, our editors use SharedArrayBuffer, a modern JavaScript feature which uses multiple JavaScript threads to share the same memory space.

We knew that choosing SharedArrayBuffer meant initial limited support for Safari - but we also guesstimated that by the time WebContainers reached stability, SharedArrayBuffer should ship in Safari. We were quite close - WebContainers became stable in March 2022 and SharedArrayBuffer officially landed less than a year later.

We had a choice. We knew that we could decide against WebAssembly threads or use a hacky walkaround and make WebContainers work on iOS a long time ago. But we chose to not do that. Instead, we embraced the direction where the web was going. By joining the Bytecode Alliance, we are able to build the web we want to see, more effectively. We wanted to build something that will inspire and lead others towards the things you can do with browsers. The decision couldn’t be more correct in retrospect - millions of developers use WebContainers on a monthly basis. And, because we choose the future, we are trailblazers in spotting bugs like the recent M1 issue, or the one with threads in Firefox. Also, not only did we spot a COEP bug in Safari but our engineer Roberto Vidal debugged it and provided a test case to speed up the resolution:

WebKit bug reporting page

At this point, we’d love to give a shoutout to Chris Dumez, WebKit contributor at Apple, who helped us with a quick turnaround with the bug. We really appreciate that 💙

Today, the tools that were once deemed “too modern” are already here - and we’ve built and optimized our architecture around them. As a result, WebContainers run in complex projects like Codeflow or SvelteKit’s tutorial, significantly faster than locally.

And we are still optimizing.

StackBlitz is all about building for a sustainable future - and not for the past. We have time and as the web is catching up, we are improving our tools, growing our community, and finding new pathways to support Open Source ecosystem in meaningful ways.

Running Node.js apps on Safari

Besides SharedArrayBuffer landing in the browser, also other changes and improvements needed to be in place for WebContainers to run on Safari.

Most developers don’t think much about the differences between browsers - not only in terms of the UI but also how they actually work and why. Each browser has its own rendering engine (Blink in Chrome, WebKit in Safari, Gecko in Firefox) responsible for drawing text and images on the screen - in other words, working with HTML and CSS. Each browser also has its own JavaScript engine, which executes JavaScript code. These are: V8 for Chrome (also used in Node.js), JavaScriptCore in Safari, and SpiderMonkey in Firefox. (A fact that may not be commonly known is that every iOS browser “must use the appropriate WebKit framework and WebKit JavaScript”. This means that under the hood every browser used on iOS and iPadOS is effectively a reskinned version of Safari.)

Both the rendering and the JavaScript engines are built in reference to specs, which provide some clarity on what should happen when certain code is executed. However, there are many areas unspecified by a spec, in which case browser vendors interpret it in their own ways and extend it according to their goals. This results in browser incompatibility, which most commonly comes to light when your carefully-designed website is run on a browser different than yours. In our case, we needed to tackle two main discrepancies: stack traces, and memory allocation.

Error stack traces

Let’s start with error stack traces, which is the information provided to you by an Error instance about which functions were called, in which file and line, and in which order. Given that the Chrome’s stack trace looks like that of Node.js, it may come as a surprise to you that we can’t programmatically rely on and assume that other browsers follow the same format. In fact, they do not. Let’s have a look at stack traces in Safari and Chrome:

Stack traces in Chrome, Safari, and Firefox

In order for any project to work across all browser environments, we needed to make sure that there was a high degree of uniformity, also in stack traces. Sam Verschueren ironed out these differences. He explained the process in the following way:

Chrome enables prepareStackTrace, which means that you can access information like line number, column number, file names, method names. You can get it natively out of V8 as a neat object with all the information. However, that’s not the case with SpiderMonkey (Firefox) or WebKit (Safari).

With WebKit and SpiderMonkey one needs to parse the blob of text to get out the line number and file name. Also, you cannot infer all of the information - nor is all of the information there. And because WebKit does not support sourceMappingURL, you also can’t rename the generated bundles.

This is not the first time, we had to tackle stack trace discrepancies - a year ago, our engineer Roberto Vidal described the process of bringing WebContainers to Firefox, as well as the bugs we spotted along the way.

Memory allocation limitations

Once we dealt with stack traces and WebContainers ran on desktop Safari, there was another obstacle: the memory constraints on mobile devices. Even though an iPhone has up to 8 GB RAM, not all of this memory can be allocated to running processes inside the browser. In other words, there are strict limitations on how much memory a webpage can use. Dominic Elm took a few hours to investigate the blockers and debug it on his iPhone and iPad to see which solutions offered the best fit. To address the memory limitation hurdle, we restricted the amount of memory WebContainers are allowed to consume on mobile devices and have been enjoying browsing docs that feature StackBlitz playgrounds ever since.

That said, there still is an existing limitation resulting from how Safari handles memory management on mobile devices (and sometimes, also desktop ones), which result in memory leaks when you refresh a page. Dominic Elm explains the problem in the following way:

When WebContainer boots, it allocates a bunch of memory, for example for the file system. With other browsers, when a browser tab or page is reloaded, all resources (including allocated memory) for that tab should be freed so that they can be reused.

However, in Safari on mobile devices if you reload the page, the resources do not always seem to be freed. This means that you may run into “Out Of Memory” issues on a second load.

In the meantime, we have implemented an intermediary workaround - a redirect to another domain when we detect iOS/iPad, and back to the original page, which forcer Safari to free the resources. However, ideally this wouldn’t be necessary so we are monitoring this bug report on WebKit.

WebContainer compatibility today

This means that today, WebContainers are supported on all devices and in all recent desktop browsers, namely:

Desktop browsers

  • Chrome: full support.

  • Other Chromium-based browsers: full support. Some browsers may apply restrictive rules by default, and require specific configuration, like Brave.

  • Firefox: beta support (see details).

  • Safari: beta support since Safari 16.4 (see details).

Mobile browsers

  • Android: beta support for Chrome, Chromium-based browsers and Firefox. Depending on your device, large projects may run into memory limitations.

  • iOS and iPadOS: beta support for Safari since iOS 16.4. Large projects may run into memory limitations because the memory usage for a web page on a mobile device is more constrained. In this case, we recommend switching to a Desktop browser that is less constrained and has more memory.

What’s next?

WebContainer support for Safari is in beta. We dearly invite you to stress-test it and tell us about it. As with any new feature or compatibility, we expect that we haven’t squashed all bugs yet and hope you will join us in this jolly hunt.

Meanwhile, our team members are looking to extend the experience even further:

A TV showing WebContainers booting up using Xbox

WebContainers booting up using Xbox

Jokes aside, we dedicate this year to not only shipping much-requested features but also improving the Developer Experience across all StackBlitz tools.

This quarter alone we will be shipping major improvements, for which we’ll need folks who use StackBlitz and would love to test them:

Tweet that reads: Help needed Do you use StackBlitz or Codeflow, often or occasionally? We are about to roll out some major improvement and we need folks to test it (and, ideally, break it!). Wanna help? DM me!

We love the web and it is our mission to push the it forward - thank you for helping us make this journey exciting.

DevRel & front-end at Stackblitz. Tech writer and educator advocating for accessible and equitable tech.