Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cwrc/leafwriter-worker-validator

Package Overview
Dependencies
Maintainers
3
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cwrc/leafwriter-worker-validator

webworker to handle validation on Leaf-Writer

  • 1.0.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
3
Weekly downloads
 
Created
Source

CWRC-Worker-Validator

================

JSDOM inside webworkers

From JSDOM documentation

https://github.com/jsdom/jsdom#running-jsdom-inside-a-web-browser

Running jsdom inside a web browser jsdom has some support for being run inside a web browser, using browserify. That is, inside a web browser, you can use a browserified jsdom to create an entirely self-contained set of plain JavaScript objects which look and act much like the browser's existing DOM objects, while being entirely independent of them. "Virtual DOM", indeed!

jsdom's primary target is still Node.js, and so we use language features that are only present in recent Node.js versions (namely, Node.js v8+). Thus, older browsers will likely not work. (Even transpilation will not help: we use Proxys extensively throughout the jsdom codebase.)

Notably, jsdom works well inside a web worker. The original contributor, @lawnsea, who made this possible, has published a paper about his project which uses this capability.

Not everything works perfectly when running jsdom inside a web browser. Sometimes that is because of fundamental limitations (such as not having filesystem access), but sometimes it is simply because we haven't spent enough time making the appropriate small tweaks. Bug reports are certainly welcome.

Discussion

https://github.com/jsdom/jsdom/issues/245 https://github.com/jsdom/jsdom/issues/1284 https://github.com/jsdom/jsdom/issues/2427

How To use JSDOM on CWRC-WRITER Web Worker

A browserified and fixed verion of jsdom (v. 16.6.0) is aleready in place on the webworkers folder /src/webworkers/lib/jsdom

If the file needs to be updated or regenerated, follow these steps:

  1. Install JSDOM and Browserify npm i -D jsdom browserify

  2. Browserify jsdom npm run browserify-jsdom (check package.json for the details)

  3. Fixes

3.1 fix AsyncIteratorPrototype AsyncIteratorPrototype is throwing an error when running on workers. Since we don't use this method, we just return it as an empty objects.

  • Open /src/webworkers/lib/jsdom/jsdon-browserified.js`
  • locate the line where AsyncIteratorPrototype is defined.
  • replace this line: const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {}).prototype);
  • for this one: const AsyncIteratorPrototype = {};

3.2 fix SharedArrayBuffer SharedArrayBuffer is throwing an error when running on workers. Since we don't use this method, we just return it as an empty objects.

  • Open /src/webworkers/lib/jsdom/jsdon-browserified.js`
  • locate the line where sabByteLengthGetter is defined.
  • eplace this line: const sabByteLengthGetter = Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength").get;
  • for this one: const sabByteLengthGetter = {};

Keywords

FAQs

Package last updated on 21 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc