Skip to content

jeromeetienne/console4Worker

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

console4Worker is console.* API for WebWorkers.

WebWorkers are hard to debug. On top of that, console.* API is unavailable in WebWorkers. It doesn't help. console4Worker is a simple library which try to fill this gap. See the demo in the examples/ directory.

On the Worker Side

First you include the script with

importScripts('console4Worker-worker.js');

Then you use console.* as you would normally do. Lets say something like

console.log("console call made from inside a webworker");

On the Page Side

To include the script, simply do

<script src="console4Worker-page.js"></script>

Then in your message event listener, add the following line

if( console4Worker.filterEvent(event) )	return;

So you should have something like

worker.addEventListener('message', function(event){
    // filter this event if it is from console4Worker
    if( console4Worker.filterEvent(event) )	return;

    // ...
    // here handle your own events

}, false);

how does it work ?

a console.* object is declared in the worker. It intercepts all console.* calls and pass them to the page thread. a direct approach.

About

console.* API for WebWorker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published