safejs
This repo intends to safely run JavaScript into a website using web workers. It provides a controller class, with some defaults.
Blog Post Link
Decipad Blog Link
Usage example
const myWorker = new SafeJs(
(successMessage) => {
console.log(successMessage);
},
(err) => console.error(err),
{
maxExecutingTime: 50000,
}
);
myWorker.execute('return "Hello World"');
Parameters
As seen above, the third parameter for the SafeJS constructor is a series of options.
export interface SafeJsOptions {
maxWorkerReturn: number;
maxExecutingTime: number;
maxConsoleLog: number;
extraWhitelist: Array<string>;
fetchProxyUrl: string | undefined;
}
dev install
to test this package you need to set up with link (insert zelda pun):
In this repo:
pnpm link
Wherever you are using it
pnpm link "@decipad_org/safejs
If you use a builder, like webpack, you might have to rebuild. This is an example of how that might look like (in the safejs repo):
pnpm run build
Inspiration
This package was partially inspired by (Wumpus World)[https://github.com/Domiii/WumpusGame/blob/master/js/script/GuestScriptContext.js]