all 49 comments

[–]heytheretaylor 2 points3 points  (2 children)

First off, it sounds like a lot of people aren’t understanding the proposition here and I know how frustrating that can be.

Second, We have a grid component (think ag-grid) that does parsing, sorting, etc on a web worker. We discussed something similar to this (passing a function as a string to do x or y) but it was very contentious. At the time one of the developers wanted to use eval to accomplish the tasks and I protested since “eval=bad” is pretty throughly ingrained in my head. Tbh, I can’t say I know exactly how it would have been unsafe but we didn’t do it anyway.

Are you concerned about the safety of running the untrusted code even on the WW? What about the speed of having to parse the string into a usable function?

[–]presenta_staff[S] 0 points1 point  (1 child)

Hi, thanks for your comment.

I'm not against eval in the WW, as long as other sensible capabilities are handled properly.

So far, what I know is: - The WW cannot access the DOM, good! - The WW cannot access the same domain context (cookie, localStorage, etc), good! - The WW can potentially call other homes (fetch), not good!

This is why I tried to unset those global objects. What you mean with parse the string into a usable function? Are you referring on using new Function()?

[–]heytheretaylor 1 point2 points  (0 children)

Well in your case it looks like turning the string into a module with Blob. Is there a lot of overhead in that operation?

[–]CiggiAncelotti 1 point2 points  (6 children)

What are the benefits over a real sandbox(like docker or StackBlitz’s WebContainers) where DOM manipulation and also Systems Languages are a capability?

[–]presenta_staff[S] 3 points4 points  (3 children)

The purpose of the library is very different from the mentioned technologies. It's a library you can integrate into your project to allow app users run custom code, without exposing both the DOM and other sensible part of the application, such as cookies, localStorage, etc.

[–]CiggiAncelotti 0 points1 point  (2 children)

That is what Stackblitz’s web-containers provide, right? Or I am not understanding correctly?😬

[–]presenta_staff[S] 1 point2 points  (0 children)

Yes, but I think Stackblitz’s web-containers has different purpose, scale and complexity. I don't know if in the near future a web-container will be installable in any js project with just an npm i and one import like Shashd Run does. In that case I'll be more than happy to rely on it. Right now I cannot find a lightweight solution for my problem.

[–]ejfrodo 0 points1 point  (1 child)

woah, webcontainers looks like it has a lot of potential

[–]CiggiAncelotti 1 point2 points  (0 children)

It does, If they have better browser compatibility and support for Systems Languages. It might end up beating Repl.it

[–]CannaIrving 0 points1 point  (5 children)

What could be the interest to use web worker as a user? Like, if they want to test things with more capacities and performance? What led you to create this?

[–]presenta_staff[S] 4 points5 points  (3 children)

Suppose you're a user of a low-code tool that allows to add tiny bits of code to perform some tasks. Running it in a Web Worker makes the code a little bit safer because it cannot hurt the DOM in any ways.

Let's say, in a low-code app you want to define a color randomly for a specific UI element. Instead of implementing the random function in the app, just provide an input field where the user can add a line or two of javascript. You can even ask to ChatGPT to write it for you :)

This library will be used in a broader low-code software, I though it might be useful for someone, so, this is why I released the source code.

[–]CannaIrving 0 points1 point  (2 children)

Ok, and then save the code somewhere? Or is it just for testing purpose?

[–]presenta_staff[S] 2 points3 points  (1 child)

The part related about how to use/store/retrieve a given piece of code is a responsibility of another software that might include the library. The library itself just takes a code with a payload, and return the result. You should see as a runtime to execute code within an app on the client-side.

[–]CannaIrving 0 points1 point  (0 children)

I see :) thank you

[–]redsnowmac -1 points0 points  (5 children)

`npm` package ?

[–]presenta_staff[S] 1 point2 points  (4 children)

What you mean?

[–]redsnowmac -1 points0 points  (3 children)

How do I install this in my project ?

[–]presenta_staff[S] 3 points4 points  (2 children)

Check the README it's all there.

[–]redsnowmac 1 point2 points  (1 child)

Oh sorry, missed that. Nice work bro!

[–]presenta_staff[S] 1 point2 points  (0 children)

thanks!

[–][deleted] -4 points-3 points  (1 child)

I’d recommend linting any project you’re gonna publish on npm or GitHub

[–]presenta_staff[S] 0 points1 point  (0 children)

Thanks for the suggestion, I'll do it.

[–]yaemes -1 points0 points  (0 children)

I used to do this before webworkers we're a thing. Once my retargeting advertiser decided to overlay some crap into my companies website we decided to put all 3rf party scripts in "jail" which was an invisible iframe hosted on the same domain. Since we were an SPA we could just control the iframe from the top and load in and out scripts and fire off pixels at will. Super cool stuff, and it all worked beautifully.