TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How to build a plugin system on the web and also sleep well at night

685 点作者 rudi-c将近 6 年前

19 条评论

osrec将近 6 年前
This is one of the cleverest things I&#x27;ve seen in JS in a while.<p>In a nutshell, they use a same origin iframe to ensure the plugin gets its own copy of globals (so it can&#x27;t mess up the globals your app uses), coupled with a proxy object which whitelists certain globals for the plugin to use along with certain vars from your app.<p>Really rather clever, although the guys who develop browsers should consider an API for something like this as it&#x27;s becoming such a common use case.
评论 #20771302 未加载
评论 #20771928 未加载
评论 #20771325 未加载
评论 #20771499 未加载
评论 #20773333 未加载
gfodor将近 6 年前
wow, we are literally working this problem right now, and I made an off hand comment that it&#x27;d be nice if Figma shared how they did their plugins. thank you for this!<p>edit: having now read the article, this is amazing, lots of get insights here. one question to the author if you are reading: it seems like it would be a worthy idea to open source the 500 line, security-sensitive interface Realm-shim. Selfishly, we would use it, but also, we (and surely others) would add eyeballs to it to ensure it&#x27;s correct. Since it&#x27;s a small slice of the system, and agonistic to the product itself, it seems unlikely to be part of any kind of technical competitive advantage. Any plans to do so?
评论 #20788006 未加载
评论 #20771674 未加载
lwansbrough将近 6 年前
Well I&#x27;m surprised I haven&#x27;t seen it yet, but I&#x27;m using Google Caja[0] for my own side project[1] (which, actually, I haven&#x27;t touched in a while..) This allows plugin developers to create fully custom HTML plugins that run in the same frame (which is crucial for AudioNodes to be operated on by multiple plugins in my case.) Example of a plugin: <a href="https:&#x2F;&#x2F;github.com&#x2F;lwansbrough&#x2F;attack&#x2F;blob&#x2F;master&#x2F;src&#x2F;plugins&#x2F;push2-test.html" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lwansbrough&#x2F;attack&#x2F;blob&#x2F;master&#x2F;src&#x2F;plugin...</a><p>Actually my demo goes as far as showing how one plugin can register a resource that is then used by another plugin. In this case I developed a plugin which registers a high level interface for access to an Ableton Push 2 device, and then another plugin uses that interface to draw to the Push&#x27;s display using the canvas API. <a href="https:&#x2F;&#x2F;twitter.com&#x2F;lwansbrough&#x2F;status&#x2F;1125842014128312320" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;lwansbrough&#x2F;status&#x2F;1125842014128312320</a><p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;caja" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;caja</a> [1] <a href="https:&#x2F;&#x2F;github.com&#x2F;lwansbrough&#x2F;attack&#x2F;blob&#x2F;master&#x2F;src&#x2F;areas&#x2F;daw&#x2F;components&#x2F;plugin&#x2F;Plugin.vue" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lwansbrough&#x2F;attack&#x2F;blob&#x2F;master&#x2F;src&#x2F;areas&#x2F;...</a>
评论 #20788029 未加载
评论 #20774498 未加载
hn_throwaway_99将近 6 年前
I know I&#x27;m just piling on (positively), but this was <i>such</i> as excellent post. Honestly, I think my biggest reaction after reading this was how amazing the engineering culture must be at this company. Working at a startup, with a relatively small team, but still having the luxury of all that time to try out multiple different approaches, get feedback, can the ones that didn&#x27;t work without making it feel like a &quot;failure&quot; in any way.<p>Major, major kudos. This is how engineering should be done.
kaiby将近 6 年前
I really like Figma&#x27;s engineering blog. I find that they do a great job introducing the concepts that need to be understood with the level of detail in their implementation of those concepts. I&#x27;m always learning something new when I read an entry.<p>This is the first time I&#x27;ve heard of Realms API or QuickJS, will need to keep those in mind if I ever need to write a plugin system.
billconan将近 6 年前
Thank you very much! this is very helpful for me. I&#x27;m making <a href="https:&#x2F;&#x2F;epiphany.pub" rel="nofollow">https:&#x2F;&#x2F;epiphany.pub</a> , it also needs to run users&#x27; code. I thought iframe was the only viable way to run third parties&#x27; untrusted code, I have never heard of Realms shim. I will looking into it!
评论 #20772657 未加载
评论 #20770643 未加载
pfrrp将近 6 年前
Related work by the AMP team is their worker dom project: <a href="https:&#x2F;&#x2F;github.com&#x2F;ampproject&#x2F;worker-dom" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ampproject&#x2F;worker-dom</a><p>The gist is to mirror a subset of DOM apis in workers and project changes back out to the main page.<p>As far as I know a few companies have tried similar methods, but most write proprietary APIs, rather than using the DOM.<p>Still in development but the examples are promising.
jackcarter将近 6 年前
I learned about Figma recently, in this HN-frontpage article about fast software: <a href="https:&#x2F;&#x2F;craigmod.com&#x2F;essays&#x2F;fast_software&#x2F;" rel="nofollow">https:&#x2F;&#x2F;craigmod.com&#x2F;essays&#x2F;fast_software&#x2F;</a><p>It really is delightfully fast. It&#x27;s no surprise that the team behind it is producing this caliber of content.
jasonmcaffee将近 6 年前
Has anyone tried running the solution? It doesn&#x27;t seem to work... The below code results in the console logging the document object, which has the document object, and the code hits a ReferenceError when trying to log the &#x27;a&#x27; variable. Calls to p.whateverPropYouMakeUp result in the log &#x27;get for target: ...&#x27;<p><pre><code> const proxyHandler = { get(target, name){ console.log(`get for target: `, target, name); return &#x27;tacos&#x27;; }, } const p = new Proxy({}, proxyHandler); with (p){ console.log(`document with proxy: `, document); console.log(`access random property: `, a); } </code></pre> <a href="https:&#x2F;&#x2F;jsfiddle.net&#x2F;wf02n4gs&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jsfiddle.net&#x2F;wf02n4gs&#x2F;</a>
评论 #20772826 未加载
kodablah将近 6 年前
Pardon my ignorance, but what if my JS was &quot;for (;;) {}&quot;? Can this handle heavy-CPU plugins? Maybe in a service&#x2F;web worker? Part of the Realm API being a good use case for plugins I assume would include this kind of isolation but I admit to not having looked in detail.
评论 #20771894 未加载
评论 #20771892 未加载
warpech将近 6 年前
Prior work in this area: <a href="http:&#x2F;&#x2F;www.adsafe.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.adsafe.org&#x2F;</a>. It is a dated library targeted at safe DOM manipulations. However, it was researched quite carefully (see the PDFs in the left column)
zawerf将近 6 年前
This post was such a ride.<p>At one point they found a fucking legitimate reason to compile a javascript interpreter to javascript(wasm) to run javascript!
welder将近 6 年前
Can&#x27;t wait for the ability to trigger plugins on events instead of having to select them from a menu [1]. That would open the door to many more useful plugins running automatically for ex every time a file is saved.<p>1: <a href="https:&#x2F;&#x2F;www.figma.com&#x2F;plugin-docs&#x2F;whats-supported&#x2F;#trigger-plugin-code-on-events" rel="nofollow">https:&#x2F;&#x2F;www.figma.com&#x2F;plugin-docs&#x2F;whats-supported&#x2F;#trigger-p...</a>
评论 #20771176 未加载
unnouinceput将近 6 年前
Plugins. The security nightmare of desktop applications and the main reason Google store &#x2F; Apple store is banishing developers accounts left and right. Like Schneier always said &quot;you can always create an unbreakable security for you but smarter ones will find holes in it&quot;. I&#x27;m curious how this one will hold on long term, let&#x27;s say an year from now.
评论 #20778885 未加载
pbreit将近 6 年前
I think PayPal tried something like this awhile back that did not get much traction.<p>&quot;PayPal Apps&quot; Developer Guide (2010): <a href="https:&#x2F;&#x2F;www.paypalobjects.com&#x2F;webstatic&#x2F;en_US&#x2F;developer&#x2F;docs&#x2F;pdf&#x2F;PayPalApp.pdf" rel="nofollow">https:&#x2F;&#x2F;www.paypalobjects.com&#x2F;webstatic&#x2F;en_US&#x2F;developer&#x2F;docs...</a>
评论 #20772310 未加载
ralmeida将近 6 年前
That&#x27;s a very interesting topic! Does anyone know of other resources (blog posts or books) talking about how to build such extensibility in a SaaS app?<p>Obviously, there are lots of inspiration to be drawn from apps we use everyday, such as GitHub, JIRA, etc, but these behind the scenes view is very informative.
评论 #20771076 未加载
felixfbecker将近 6 年前
with (new Proxy()) { eval() } blows my mind.
NullPrefix将近 6 年前
What&#x27;s figma?
评论 #20770767 未加载
评论 #20770920 未加载
评论 #20771264 未加载
评论 #20771311 未加载
musicale将近 6 年前
Third-party and&#x2F;or untrusted javascript is obviously a massive security and privacy hole if you don&#x27;t put it in an iframe.
评论 #20771666 未加载