web-worker

Web workers and accessing object attached to the window object

ぐ巨炮叔叔 提交于 2019-11-28 00:20:21
I have an ember application that I create like this: window.App = Ember.Application.create({}); I want to do some background processing on a web worker. How can I get access to the window object or some other global object in the separate web worker thread? Jivings Short answer. You can't. The only resources available to web workers are that which they load from JavaScript files using importScripts() or anything that is passed to them via postMessage() . You can however now pass Objects to them. They are serialized and de-serialized to JSON automatically. Also, there is no access to local

Parsing XML in Web Workers

好久不见. 提交于 2019-11-27 21:48:15
问题 I know the Web Worker spec says "no access to DOM because DOM is not thread safe". While I can see that's logical for web workers and the HTML page DOM, it's actually very restrictive when considering parsing XML from an XmlHttpRequest call - after all, the basic handling of that call is asynchronous and so has little effect on the foreground thread, it's the parsing of the XML that slows down the foreground thread (when dealing with XML apps). Is there any way other than building my own XML

Reliably detect if the script is executing in a web worker [duplicate]

空扰寡人 提交于 2019-11-27 21:17:02
问题 This question already has an answer here: Any standard mechanism for detecting if a JavaScript is executing as a WebWorker? 5 answers I am currently writing a little library in JavaScript to help me delegate to a web-worker some heavy computation . For some reasons (mainly for the ability to debug in the UI thread and then run the same code in a worker) I'd like to detect if the script is currently running in a worker or in the UI thread. I'm not a seasoned JavaScript developper and I would

Pass large amounts of data between web worker and main thread

不问归期 提交于 2019-11-27 20:55:56
问题 Is there a way to pass large amounts of data (multiple MB) between a web worker and the main thread? I work in a project where I need to download files, modify them a bit and then somehow let the user download the modified file. I found the following ways to pass data between a web worker and the main UI Using the regular postMessage method. Using transferable objects (Chrome only) Create a URL reference to a blob and only send the URL (works in Chrome, in others as well?) I think (1) is fine

How to apply web worker to rendering of a PDF using makepdf

為{幸葍}努か 提交于 2019-11-27 18:59:32
问题 I successfully created a PDF using a JavaScript plug-in (pdfmake) and it was great. But when I try to render an ~8,000-row inventory/ledger printout, it freeze for over a minute. This is how I usually declare my docDefinition var docDefinition = { pageOrientation: orientation, footer: function(currentPage, pageCount) { return {text: currentPage.toString() + ' / ' + pageCount, fontSize:8, alignment:'center'}; }, content:[ printHeader, { fontSize: 8, alignment: 'right', style: 'tableExample',

Sharing websocket across browser tabs?

微笑、不失礼 提交于 2019-11-27 18:08:45
We want to have one socket per browser rather than one per tab in a browser. How can we achieve it? I read about shared web workers which was promising. A reference for that too is appreciated. Unfortunately shared web workers are not yet implemented by mozilla or internet explorer to the best of my knowledge. So what to do in this case ? We are working on node.js on server side. After seeing this question, I've finally implemented sharing socket and added to my library a few days ago. It seems to work in most of browsers including even in IE6, but except Opera. For Opera, you may use regular

how to pass large data to web workers

与世无争的帅哥 提交于 2019-11-27 18:08:06
I am working on web workers and I am passing large amount of data to web worker, which takes a lot of time. I want to know the efficient way to send the data. I have tried the following code: var worker = new Worker('js2.js'); worker.postMessage( buffer,[ buffer]); worker.postMessage(obj,[obj.mat2]); if (buffer.byteLength) { alert('Transferables are not supported in your browser!'); } John UPDATE : According to Mozilla the SharedArrayBuffer has been disabled in all major browsers, thus the option described in the following EDIT does no longer apply. Note that SharedArrayBuffer was disabled by

Run Angular 2 app in web worker using WebPack

瘦欲@ 提交于 2019-11-27 17:50:56
问题 I'm trying to move the whole execution of an Angular 2 app to a web worker, but I've find out that all examples available right now are using System.js, and I'm trying to do so with a WebPack based project (built with angular-cli). Has anyone done this or have an idea on how to do this with WebPack? Below is my main.ts bootstrap file: import './polyfills.ts'; import { enableProdMode } from '@angular/core'; import { environment } from './environments/environment'; if (environment.production) {

HTML5 Websocket within Webworker

感情迁移 提交于 2019-11-27 17:48:21
问题 I've managed to get websockets working inside a webworker using Chrome, but only for receiving data. When I try to send data I get a DOM Exception, has anyone managed to send data? This is what I have for my web worker. self.addEventListener('message', function(e) { var data = e.data; switch (data.cmd) { case 'init': self.postMessage("Initialising Web Workers..."); testWS(); break; default: self.postMessage('Unknown command: ' + data.msg); }; }, false); function testWS() { var connectionAddr

How fast are Web Worker's messages?

元气小坏坏 提交于 2019-11-27 17:42:49
问题 I wondered if transmission to or from a web worker can be a bottleneck. Should we post message just as we trigger any kind of events, or should we take care and try to limit as much as possible the communication between the two ? Let's have an example. If I have a huge array that is dynamically constructed (e.g. an array of contact points coming from mousemove or touchmove for a gesture recogniser), is it more efficient to transfer the data iteratively – i.e. send each element as soon as we